I am bundling a Vue UI with a Spark Java backend.
Both modules are built independently, which works fine with the following structure:
project
+-- backend
| +-- src
| | +-- main
| | +-- resources
| | +-- public <= Where the jar is picking the static files
| +-- build
| +-- libs <= Gradle Jar output
+-- ui
+-- dist <= Vue build output
On the backend, Gradle is bundling backend/src/main/resources/public
into the Jar /public
. Hence I copied from ui/dist
into backend/src/main/resources/public
as a jar
task dependency.
task copyUI(type: Copy) {
from( '../ui/dist')
into( 'src/main/resources/public')
}
jar.dependsOn( copyUI)
Gradle is copying the files but after creating the jar.
In other words, I have to create the jar twice to get it right.
How can I instruct Gradle to wait the copy completion before packaging /public
My build.gradle
jar section looks like this
jar {
manifest {
attributes(
'Main-Class': 'tld.domain.MainClass'
)
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
}
}
While what you are doing seems logical (and bug-free) to me, I don't see a reason for gradle to not wait until copying is done. May I suggest doing it little differently though.
You can directly instruct jar
task to load files from ../ui/dist
in the from
block. This way, you won't have to actually copy anything to public
dir.
jar {
// ...
from( '../ui/dist')
}
This is better as public
can stay clean of generated code (via build of ui project) and you save time of copying (and potentially issue arising because of it).
and finally make jar
task dependsOn
you UI project's build task, so that latest dist is available in ../ui/dist
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With