Slackbot
02/22/2022, 11:17 AMVampire
02/22/2022, 11:31 AMproject(...)
dependency.
Read here for information on how to properly use results from one project in the other: https://docs.gradle.org/current/userguide/cross_project_publications.htmlJo Vanthournout
02/22/2022, 1:41 PM// new configuration called bootJarArtifacts that is consumable
configurations {
bootJarArtifacts {
canBeConsumed = true
canBeResolved = false
}
}
// make an artifact available in the "bootJarArtifacts" configuration
// the artifact that is made available is the output of the bootJar task (provided by spring boot plugin)
artifacts {
bootJarArtifacts(bootJar)
}
This was on the producing side, now for the consuming side (here I am less confident I am doing it right)
// define resolvable configuration for installer resources
configurations {
installerResources {
canBeConsumed = false
canBeResolved = true
}
}
// In the new installerResources configuration, depend on the web-application project artifacts in the custom configuration "bootJarArtifacts"
dependencies {
installerResources(project(path: ":web-application", configuration: 'bootJarArtifacts'))
}
// a task that retrieves the dependencies defined in the installerResources configuration and copies them to
// the correct folder in src/main/dist/lib
def addSpringBootJarToDist = tasks.register("addSpringBootJarToDist");
addSpringBootJarToDist.configure() {
group = 'Build'
description = 'Adds the spring boot jar to the lib folder of the dist.'
doFirst {
// we currently publish only one artifact, so we depend on this --> getSingleFile
def bootJar = configurations.named("installerResources").get().getSingleFile()
copy {
from bootJar
into "$project.projectDir/src/main/dist/lib"
eachFile { details ->
details.setRelativePath new RelativePath(true, "application.jar")
}
}
}
}
Jo Vanthournout
02/22/2022, 1:43 PMgradle assemble
that the dependency in the web project is built first?Vampire
02/22/2022, 1:48 PMsrc/main/dist
.
src/main/dist
is for checked in things to copy into the distribution, not for build artifacts.
Configure the distribution instead.
Something like (untested):
distributions {
main {
contents {
from(configurations.installerResources)
into('lib')
}
}
}
Jo Vanthournout
02/22/2022, 1:49 PMJo Vanthournout
02/22/2022, 1:49 PMJo Vanthournout
02/22/2022, 1:49 PMVampire
02/22/2022, 1:50 PMVampire
02/22/2022, 1:50 PMVampire
02/22/2022, 1:51 PMand fewer lines of codeAnd it should actually work opposed to your version. :-D
Jo Vanthournout
02/22/2022, 1:53 PMVampire
02/22/2022, 2:31 PMCopySpec
and so can use anything also usable there. 🙂Jo Vanthournout
02/22/2022, 4:11 PMJo Vanthournout
02/22/2022, 4:11 PMVampire
02/22/2022, 6:54 PM