My backend builds a .jar file for deployment but it needs some files that are generated in the shared-resources and frontend subprojects.
So my frontend subproject generates some javascript files that we need in the jar of the backend
and the shared resources generates some css files that need to be in the jar of the backend too.
How do I make sure that that the backend module is build as last.
In my backend build.gradle I have the following task:
task resolveFrontendCode(type: Copy) {
from "${project.rootDir}/frontend/dist"
into "${project.buildDir}/resources/main/static/js"
from "${project.rootDir}/shared-resources/src/main/webapp/css/build"
into "${project.buildDir}/resources/main/static/css/build"
from "${project.rootDir}/shared-resources/src/main/webapp/images"
into "${project.buildDir}/resources/main/static/images"
it.dependsOn 'buildClientSideCode'
}
compileJava.dependsOn(resolveFrontendCode)
this task will copy the generated files into the backend project but it seems that my other subprojects are build first.
the buildClientSideCode task that it dependsOn is both defined in frontend and shared-resources
I’m hoping someone could point me in the right direction. Gradle is rather new to me.
If that is set up correctly, Gradle will always execute things in the right order.
If you need to share other artifacts than the jar file(s) (which are the default artifacts if you built Java projects) you can define your own artifacts. You can also set that up without applying a Java plugin at all, if you are not compiling Java sources. Please have a look at the documentation on Sharing outputs between projects. Let me know if you are stuck with something in your non-Java centric use case.
There are quite some improvements in this area with the latest Gradle 5 and Gradle 6 versions. So I would recommend using the latest Gradle version if you can.
Yet when I specify the task to depend on buildClientSideCode it does not work correctly.
I did solve it for now based on the projects maven setup. I guess for that is currently what we need. Any optimisations are definitely made but we’ll take it one step at a time
I have now the following setup which works perfectly for me right now while I look at the docs you gave me to alter anything
task resolveFrontendCode(type: Copy) {
into project.buildDir
into("resources/main/static/js") {
from "${project.rootDir}/frontend/dist"
include "**/*.js"
}
into("resources/main/static/css/build") {
include "**/*.css"
from "${project.rootDir}/shared-resources/src/main/webapp/css/build"
}
into("resources/main/static/images") {
from "${project.rootDir}/shared-resources/src/main/webapp/images"
}
// This task depends on the buildClientSide Tasks for both the frontend and shared-resource
// subprojects. These need to be build before we can copy the build files.
it.dependsOn ':shared-resources:buildClientSideCode'
it.dependsOn ':frontend:buildClientSideCode'
}
Thank you very much for that link that looks to be what I need.
The project has some bigger dependency issues that can be optimised further though, but this has helped me to at least get the project completely running under gradle