I’ve got an use case for what the subject describes. I’ve got a build system that should treat a source repository as a black box, that is, invoke the build without modifying the sources. Additionally I need extra information provided by plugins that may not have been configured in the build, such as jdeps and jdeprscan.
In the Maven world this is as easy as invoking mvn groupId:artifactId:version:targetId; provided the plugin can be resolved from the repositories configured in the POM file (AFAICT). Sadly, there’s no equivalent syntax found in Gradle.
The first alternative I thought of was to create another script with the additional plugin config in place, importing the main build file, then instructing gradle to use the new build file, such that
my-custom-build.gradle
buildscript {
repositories {
}
dependencies {
classpath 'org.kordamp.gradle:jdeps-gradle-plugin:0.3.0'
}
}
apply plugin: 'org.kordamp.jdeps'
apply from: 'build.gradle'
Then invoke gradlew -b my-custom-build.gradle jdeps which unfortunately fails. The next option was to append the required customizations to the main build file, but this will cause trouble depending on how the main build file defines plugins.
-
If it uses
buildscriptthen all is OK as you can have multiplebuildscriptblocks. Still feels odd somehow. -
If it uses
pluginsand customizations usebuildscriptthen results in Failure with the following error printed to the output "all buildscript {} blocks must appear before any plugins {} blocks in the script
See https://docs.gradle.org/4.6/userguide/plugins.html#sec:plugins_block for information on the plugins {} block"
- If it uses
pluginsand customizations usepluginstoo then it results in Failure again with the following error printed to the output "only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
See https://docs.gradle.org/4.6/userguide/plugins.html#sec:plugins_block for information on the plugins {} block"
Thus the append option works for 1/3 of the possibilities. Is there any other way to make this behavior work, similarly as it’s done with Maven?