Reputation: 45
I'm quite new to Gradle. And it shows. We have a build.gradle that builds a Docker image using the plugins found in the com.bmuschko:gradle-docker-plugin:3.0.11 and de.undercouch.download:3.3.0 artifacts. The image is created via the com.bmuschko.docker-remote-api plugin after a set of assets (files) are fetched via the Download task provided by the de.undercouch.download plugin. Works great.
Here is a snippet of our build.gradle, hopefully the usage is pretty clear. A bit fudged to save space.
task buildImage( type: DockerBuildImage){
dependsOn "gatherAssets"
... other properties
}
task gatherAssets( dependsOn ["task1","task2",..."taskN" ] ) {
doLast {
println 'Gathering Assets for ' + imageName
}
}
task task1(type: Download) {
src "${NEXUS_DOWNLOAD_ROOT}/org/alfresco/alfresco-mmt/${MMT_VERSION}/${ALFRESCO_MMT_JAR}"
dest Paths.get(ASSETS_DIR, ALFRESCO_MMT_JAR).toFile()
}
What I want to do now is use a Maven repository to grab at least 1 of the assets. Using module dependency would be ideal - specify the repository, the modules & let Gradle do its thing. Especially if I use a virtual repository to allow patched assets to be used. Without having to change the build.gradle script. If the patched dependency is in the local (1st physical) repository, grab it.
I was hoping, based on the (https://docs.gradle.org/5.2.1/dsl/org.gradle.api.Task.html#org.gradle.api.Task:dependsOn)
stating that dependsOn is just a Set<Object>, that while currently we have a set of task names, why not expect that for each such name in the dependsOn set, if a task is not found by that name, perhaps a module name is declared & so use it as a dependency to be resolved & utilized?
like this:
task gatherAssets( dependsOn ["mms-amp","task2",..."taskN" ] ) {
so gatherAssets would dependsOn a set of explicit dependency references and Gradle tasks... Alas, in v5.4.1, not so.
I cannot find what configurations exist for plugins other than 'java' for which I can use the dependency construct. I was hoping that using
apply plugin 'java'
would give me the implementation configuration, thus allowing the following:
dependencies {
// note that when we uploaded the amp artifact to the local repo, we had a POM generated.
// Gradle will fetch the pom, parse it to get the details on what to download... like an *.amp
// because we provide not-default properties for the dependency artifact.
implementation( group:'edu.stevens.serc', name: 'mms-amp', version: ${version} ) {
artifact {
name = 'mms-amp'
extension = 'amp'
type = 'amp' // needed ?
}
}
}
An obvious newbie question:
what is the general form for an reference to a dependency? And am I a bit naive hoping the notion of dependencies in Gradle isn't just for Java builds? I will scream outloud if that's the case...
In my example above, isn't "mms-amp" the name of the 1 dependency I've declared? Hence my misplaced hope that using the dependency name "mms-amp" in the dependsOn set would be sufficient.
Is the use of Maven repositories baked into Gradle, that the 'maven' plugin is just for publishing artifacts to a repository?
MTIA for any insights, pointers to better plugins to use, etc.
Upvotes: 1
Views: 704
Reputation: 45
an answer. sort of. I ran across the 1st example in https://docs.gradle.org/5.2.1/javadoc/org/gradle/api/artifacts/ConfigurationContainer.html that showed exactly what my question hopefully detailed what I was trying to achieve.
It's still not clear to me the type details - why the Copy task's from method can take an object of type ConfigurationContainer but that's for me to figure out. It's pretty powerful that it can. From the above link, here is the snippet:
//copying all dependencies attached to 'compile' into a specific folder
task copyAllDependencies(type: Copy) {
//referring to the 'compile' configuration
from configurations.compile
into 'allLibs'
}
in my case, I used the specific configuration to fetch dependencies into an assets directory to be included in a Docker image build. And per the docs, the name of the configuration need not be on of the configurations used by the java plugin. I used a project-specific configuration so as to keep the set of dependencies disjoint from those other source dependencies.
Upvotes: 1