Hello.
I am not fully sure whether this is the right forum to ask. Depends on whether I am doing things right, then this forum might be wrong, otherwise (in case I am doing something wrong) this will be the right forum.
I have multi-module projects like this:
rootproject
- lib-project
build.gradle
- webapp-project
build.gradle
settings.gradle
As I understand it is not required (or even not good practice) to have build.gradle
in root project?
Now; When plugin is needed in both subprojects is it ok then to apply plugins to the subprojects directly or should it be declared in the root project first (maybe with apply:false).
Actual case: artifactory plugin.
Omitting build.gradle in root project I added to subprojects
./webapp/build.gradle
plugins {
id "war"
id "com.jfrog.artifactory" version "5.1.10"
}
./lib/build.gradle
plugins {
id "java"
id "com.jfrog.artifactory" version "5.1.10"
}
With this, build is working.
But as soon as I add another plugin (let’s say id "com.liferay.source.formatter" version "5.2.58"
) to only one of the subprojects the build (refresh, etc…) processes fail with
An exception occurred applying plugin request [id: 'com.jfrog.artifactory', version: '5.1.10']
> Failed to apply plugin class 'org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin'.
> Cannot add extension with name 'artifactory', as there is an extension already registered with that name.
Adding id "com.liferay.source.formatter" version "5.2.58"
to both subprojects lets the build succeed.
Adding build.gradle
to root project with
plugins {
id "com.jfrog.artifactory" version "5.1.10" apply false
}
and eventually removing version from subprojects also seems to solve the problem.
What is the quintessence of that? That build.gradle in root is basically required in case plugins are needed on all subprojects? Or is this an artifactory plugin issue?
As recommendations say to better use buildSrc/convention plugins rather than subprojects {...}
or allprojects {...}
in root build.gradle what are the usual practices here?
Background of this is, that I have a published convention-plugin project which also predefines artifactory stuff. In the projects I have e.g. lib-conventions.gradle
and web-conventions.gradle
both based on a common-conventions.gradle
file.
The latter provides the jfrog.artifactory stuff. With these plugins I basically run into the same problems concerning artifactory because for sure I virtually want to apply lib-conventions
to lib-project and web-conventions
to web-project for example (and via common-conventions
both of them apply artifactory plugin). And using my plugins this way runs into the same error when applying e.g. id "com.liferay.source.formatter" version "5.2.58"
to one of the subprojects.
This was the initial reason why I tested it with the small reproducer above without convention plugins.
One could argue and say, adding it to subprojects leads to multiple locations where version is set. But I could then maybe set a variable in gradle.properties or even better using a libs.versions.toml file then I could simply alias(libs.plugins.jfrog.arti)
on the subprojects that need it (this is basically what I am doing with my plugins and the included version-catalog) - but this unsurprisingly issues the same error.
Besides… also tested usage of id "com.jfrog.artifactory" version "5.1.10"
together with one or two other random plugins to make sure that this is not caused by id "com.liferay.source.formatter" version "5.2.58"
. Always results in the error above.
Thx!