I have to download a zip file of jars, and extract them, and use them as dependencies for Project A. I extract them in a task of Project B. I think the right way to do this is to consider all of the jars as an artifact of Project B, so that project A can depend on it. I got this almost working, currently…
Project A has the dependency on Project B’s artifact as:
apply plugin: 'java'
dependencies {
compile project(path: ':projectB', configuration: 'compile')
}
And project B is fully custom, like:
def outputDir = file("SOME_PATH")
configurations {
compile
}
task myTask {
doLast {
// in doLast because other stuff happens here
copy {
from { zipTree("A ZIP ARCHIVE") }
into outputDir
}
}
}
artifacts {
compile file: outputDir, name: 'myArtifact', type: 'directory', builtBy: myTask
}
Right now when I run assemble
on Project A, gradle does know to run myTask
, which means it sees the artifact, but the compilation fails to find any classes/jars in that directory.
My only thoughts on how to proceed:
- Is there some magical
type
that needs to be defined in the artifact that will make this happen? - Do I need to define a separate artifact for each jar extracted?
My workaround that works, but not ideal, is to have the dependency in Project A defined as:
dependencies {
def directory =
project(":projectA").configurations.compile.artifacts.getFiles().getFiles().toArray()[0]
compileOnly fileTree(directory) {
builtBy ':projectB:myTask'
}
}
But that is horrible. What should I do?