问题
I have a project with the following structure:
web-client/ # Angular Client
build/
build.gradle
server/ # Spring Boot Application
build/
build.gradle
build.gradle # The "parent" project. Works on web-client and server
The parent
is supposed to copy the compiled web-application into server/build/classes/static
such that it will be copied to /BOOT-INF/classes/
of the final jar
where it will be served by the Spring Boot server.
Everything is working so far except the last part. Those files are nor copied into the final jar
and I think it's because it got already build at the time where the copying task is executed.
This is the script which I am currently using:
task buildWebApp {
outputs.dir('mobile-client/build')
dependsOn ':mobile-client:buildWebApp'
}
task copyWebApp {
doFirst {
copy {
from 'mobile-client/build'
into 'server/build/classes/static'
}
}
dependsOn tasks.buildWebApp
}
# assemble.dependsOn copyWebApp
build.dependsOn copyWebApp
How can I make sure that those files from mobile-client/build
end up in the final jar of server
?
回答1:
Cannot guarantee its current functionality, but this I used in one of my projects a few years ago. I did use separate gradle submodule for building Frontend and then separate module for Backend where I included Frontend as a JAR:
root gradle project -> frontend
-> backend
Frontend build.gradle (builds frontend JAR with /static/**)
apply plugin: "com.moowork.node"
apply plugin: 'java'
node {
version = '8.9.3'
download = true
}
def webResources = "$buildDir/web-resources/main"
sourceSets {
main {
output.dir(webResources, builtBy: 'buildWeb')
}
}
task webInstall(type: NpmTask) {
args = ['install']
}
task buildWeb(type: NpmTask) {
dependsOn webInstall
args = ['run', 'build']
}
build.dependsOn buildWeb
Backend build.gradle
apply plugin: 'spring-boot-gradle-plugin'
apply plugin: 'idea'
dependencies {
compile project(':frontend')
}
来源:https://stackoverflow.com/questions/65645773/how-to-merge-client-and-server-builds-into-one-jar-with-gradle