gradle-node-plugin
gradle-node-plugin copied to clipboard
Add an option for disabling the default task dependencies
Same here: I have gradle backend and frontend project. And when I run assemble it automatically runs npm_install and npm_run_build which takes forever. I would like to only run the frontend part when I call gradlew jar.
Is there a workaround how to get rid of the default task dependencies?
/edit: started looking into this a bit. Maybe something would be possible with this syntax:
frontend_npm_install.onlyIf { project.hasProperty('buildFrontend') }
But I'm not sure how to set those properties, as with this:
task frontend_enable_build {
doLast {
project.setProperty('buildFrontend', 1)
}
}
I get the error: Could not set unknown property 'buildFrontend' for project ':allvisa-consult-frontend' of type org.gradle.api.Project.
/edit2: omg Intellij calls :backend:assemble which automatically causes the frontend everytime to build. So now I can't even start the backend without waiting an extra minute every time. Intellij runs 'Task :backend:assemble' automatically when I click to start the application main class.
This happens because the inputs and outputs of the tasks are not configured correctly. If it was the case, those tasks would run only if needed.
First, I advice you to read this part of the Gradle documentation which explains the concept.
Then, I advice you not to use the virtual npm_install or npm_any tasks because the inputs and outputs cannot be configured on those tasks. Instead, use the npmInstall task, maybe configure node.npmInstallCommand to ci if you want to make npm ci instead of npm install.
Create a buildFrontend or whatever name task with type NpxTask or NpmTask and define correctly its inputs and outputs. You can see an example of how to do this to build an Angular application here (it uses the Kotlin DSL).
Once this will be done, the tasks will run only when needed. They will run if something changed since last build but they will not run if everything is already up-to-date.
I don't think removing the dependencies is the appropriate solution. That would mean for instance that starting from a fresh source code checkout, running gradle build would not build the whole application.
Hope this will help you 😉