I’ve been stumped on this one for quite some time.
I’m currently generating a CopySpec from a method. I could not figure out how to “safely” replicate the war plugin behavior of providedCompile. What we’ve been doing until now is something like:
def appCopySpec(Project app, distPath, String confPath, String filterFile) {
copySpec {
def appDir = app.projectDir
def appName = app.name
// app configuration
into(confPath) {
from("$appDir/src/main/etc") {
def filterProps = new Properties()
file("$appDir/src/main/dist/${filterFile}.properties").withInputStream {
filterProps.load(it)
}
filter(ReplaceTokens, tokens: filterProps)
}
}
into(distPath) {
// app jars
into("apps/$appName/lib") {
from app.tasks.withType(Jar) // app artifact
from app.configurations.runtimeClasspath - app.configurations.providedCompile
}
...
}
Most notably the last block is what triggers the following warning:
The configuration was resolved without accessing the project in a safe manner. This may happen when a configuration is resolved from a thread not managed by Gradle or from a different project. See Troubleshooting Dependency Resolution for more details. This behaviour has been deprecated and is scheduled to be removed in Gradle 6.0
I’ve read Sharing outputs between projects and whatever posts online I could find. I’ve set it up (as far as I can tell) like in the docs.
After defining a new artifact in each subproject ‘tarball’ from the distribution plugin’s distTar task, and replacing the block:
into("apps/$appName/lib") {
from app.tasks.withType(Jar) // app artifact
from app.configurations.runtimeClasspath - app.configurations.providedCompile
}
with:
into("apps/$appName")
from(configurations.getByName(appName))
This will correctly track the dependency and trigger the distTar task needed to generate the artifact. However, I’m just using the tar to facilitate packaging of a war-like archive (in that its just an archive of runtimeClasspath minus providedCompile, but without all the WEB-INF, etc, etc.)
Changing this to use zipTree on singleFile will correctly unpack the archives and create the distribution I’m looking for. However it doesn’t seem to track the dependency correctly, even with an explicit builtBy declaration, and as such if the tar file wasnt already generated, it Gradle bails out because it cant find the archive. This can be confirmed by inspecting the taskTree in both cases.
Execution failed for task ‘:installDist’.
Could not read ‘/path/to/subproject/build/distributions/subproject-version.tar’ as it does not exist.
when using the similar:
from(tarTree(configurations.getByName(appName).singleFile))
You might find some similar posts from about a year ago on this topic, as we still haven’t figured it out. Any help is very much appreciated!