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
jartask to load files from../ui/distin thefromblock. This way, you won't have to actually copy anything topublicdir.This is better as
publiccan 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
jartaskdependsOnyou UI project's build task, so that latest dist is available in../ui/dist