I am using Gradle build tool. I have a precompiled Gradle script plugin X, lets say this is a convention plugin. In build.gradle of plugin I define dependency on another external plugin Y.
plugin X:build.gradle:
dependencies {
implementation "com.rivancic.y:y-gradle-plugin:${versionYPlugin}"
}
plugin X:gradle.properties
versionYPlugin:1.0.0
Then in my main project, I apply precompiled script plugin X and I want to manually set version of external plugin Y. Is that possible? I can't find a way to override the plugin Y version from A.
If I define in project A:gradle.properties the version
versionYPlugin=1.1.0
it doesn't help, still version 1.0.0 is being resolved.
Is there any other way if I want that external plugin version can be dynamically set?
CodePudding user response:
You are confusing projects and build time vs. application time.
X:build.gradle
is the build file of your plugin.
Before build A
can apply X
, X
needs to be built.
The build of X
is a totally separate build.
A project property you have on project A
has nothing to do with the build of X
, so cannot influence the build of X
, no matter whether this is buildSrc
, an included build, or a standalone build.
If X
is buildSrc
or an included build, you could consider some way to reuse the gradle.properties
of A during the build time, but as you want to influence from the consumer, I guess it is as standalone build or you could change it in the build of X
directly.
So as X
is probably a standalone build, when A
wants to apply it, it is already built and has a metadata file where the version of Y
is contained that was defined in X
when building it.
To use a different version of Y
, you have to make sure it is in the build script class path of A
. You could for example do plugins { id("com.rivancic.y") version "3.1.0" apply false }
so that it is in the build script class path of A and is used instead of the version that X
depends on.
Or you could define it as buildSrc
runtimeOnly
dependency just to put it to the class path of all the build scripts.
...