I'm upgrading the CheckStyle plugin at runtime, per the documentation.
However, my local and CI/CD builds fail because it appears there is dependency resolution happening in the plugin upgrade not respecting the defined repositories
in the pom.xml
.
The dependency in question holds the company checkstyle files.
Note: I've even tried adding the dependency outside the plugin as shown below. No dice.
Any hints as to how to get this to resolve? Logs follow configuration.
<repositories>
<repository>
<id>checkstyle-repo</id>
<url>https://repo/where/dependency/resides</url>
</repository>
<repository>
<id>company-repo</id>
<url>http://nexus-01.co.lan/content/groups/CompanyRepository/</url>
</repository>
</repositories>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.41</version>
</dependency>
<dependency>
<groupId>com.company</groupId>
<artifactId>co-checkstyles</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
<configuration>
<configLocation>company_transitional_checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
...
...
<dependencies>
...
<dependency>
<groupId>com.company</groupId>
<artifactId>co-checkstyles</artifactId>
<version>1.0.4</version>
</dependency>
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.985 s
[INFO] Finished at: 2021-03-11T19:14:33-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.2:check (validate)
on project tax-service: Execution validate of goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.2:check failed:
Plugin org.apache.maven.plugins:maven-checkstyle-plugin:3.1.2 or one of its dependencies could not be resolved:
Failure to find com.company:co-checkstyles:jar:1.0.4 in http://nexus-01.co.lan/content/groups/CompanyRepository/ was cached in the local repository,
resolution will not be reattempted until the update interval of corepository has elapsed or updates are forced -> [Help 1]
[ERROR]
Solved.
mvn -X
for the win.
But Holy Artifact! Batman... yeah, this is not well understood, or maybe just not well documented, and I've used maven for almost 13 years, since some of the late 1.0 and first 2.0 releases. I can't recall encountering this kind of configuration nuance in the lifecycle.
Without going into the weeds too much, maven dependency resolution has two (2) modes.
repository
pluginRepository
In the case of a plugin like CheckStyle where the classpath can be "upgraded at runtime" to use the latest checkstyle release, dependencies are resolved from a pluginRepository
.
At work, we don't generally define pluginRepositories
in our POMs and allow Maven to "default" to the project repositories
, e.g., corepository
at nexus-01
.
Turning on debug, -X
, on the mvn
runtime got me to this little bit of information...
11835 [DEBUG] === PROJECT BUILD PLAN ================================================
11835 [DEBUG] Project: com.company:tax-service:1.1.3.36cc94b4
11835 [DEBUG] Dependencies (collect): [runtime]
11835 [DEBUG] Dependencies (resolve): [compile, compile+runtime, runtime, test]
11835 [DEBUG] Repositories (dependencies): [gitlab-co-checkstyle (https://gitlab.com/api/v4/projects/nnnnnnnn/packages/maven, default, releases+snapshots), corepository (http://nexus-01.co.lan/content/groups/CompanyRepository/, default, releases)]
11836 [DEBUG] Repositories (plugins) : [corepository (http://nexus-01.co.lan/content/groups/CompanyRepository/, default, releases)]
BOOM... The CheckStyle plugin resolves dependencies from the pluginRepository
! This little bit of information told me all I needed.
I patched up the ci_settings.xml
and all was good.
11835 [DEBUG] === PROJECT BUILD PLAN ================================================
11835 [DEBUG] Project: com.company:tax-service:1.1.3.36cc94b4
11835 [DEBUG] Dependencies (collect): [runtime]
11835 [DEBUG] Dependencies (resolve): [compile, compile+runtime, runtime, test]
11835 [DEBUG] Repositories (dependencies): [gitlab-co-checkstyle (https://gitlab.com/api/v4/projects/nnnnnnnn/packages/maven, default, releases+snapshots), corepository (http://nexus-01.co.lan/content/groups/CompanyRepository/, default, releases)]
11836 [DEBUG] Repositories (plugins) : [gitlab-co-checkstyle (https://gitlab.com/api/v4/projects/nnnnnnnn/packages/maven, default, releases+snapshots), corepository (http://nexus-01.co.lan/content/groups/CompanyRepository/, default, releases)]