Hi, (I don’t know why the first code snippet is duplicating itself, it’s not doing it in my edit)
I’m writing a plugin to add dependent jars from an application server to my build. All the jars I want to add are called classes.jar, and live in various submodule directories.
e.g.
DAS/lib/classes.jar DPS/lib/classes.jar …
(this is Oracle/ATG btw).
I can’t work out the syntax for adding a file to the dependency from its absolute path, so instead I tried adding the parent directory of the jar to the repositories section, and then create a compile dependency based on the name of the file with “:” prepended to it.
This works except that all the jar files have the same name (blame ATG, not me). I can’t change the file names of the jars.
The problem with this method is clearly there’s a name clash with all the dependencies simply adding “:classes”, and not being able to differentiate the different jars.
Here’s the snippet of code i tried
def filesToAdd = []
def parentDirs = filesToAdd.collect { new File(it).parentFile }.unique()
parentDirs << directoriesToAdd
project.repositories {
flatDir dirs: parentDirs.unique()
}
// convert "myfile.jar" to ":myfile" for each file in list
filesToAdd.collect { ":" + ... }.each { module ->
project.dependencies {
delegate."compile"(module)
}
}
Can someone please shed some light on the syntax for adding an absolute named file to the build, I just can’t seem to work it out.
I’ve tried:
filesToAdd.each { file ->
project.dependencies {
classpath files(file) // gives error: 1
classpath new File(file) // gives error: 2
}
}
1 gives “No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.files() is applicable for argument types: (java.lang.String)”
2 gives “No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.classpath() is applicable for argument types: (java.io.File)”
So what’s the correct format for adding a jar whose exact filepath I know into the build?
Thanks, Mark