Providing custom checkstyles to the plugin at runtime

159 views
Skip to first unread message

Timothy Stone

unread,
Mar 12, 2021, 11:01:33 AM3/12/21
to checkstyle

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 that is 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> 
    </repository> 
    <repository> 
      <id>company-repo</id> 
      <url>
      </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> 
...

Error

[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] 

Roman Ivanov

unread,
Mar 13, 2021, 10:09:53 AM3/13/21
to Timothy Stone, checkstyle
Hi Timothy,

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/ 

This means you have problem with you own maven repo.
please work with your devops team to resolve it, we can not help you here.
We use custom extension for maven plugin all the time in CI that you can see in public (event without cache), all works fine.

thanks,
Roman Ivanov

--
You received this message because you are subscribed to the Google Groups "checkstyle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to checkstyle+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/checkstyle/550f6fbf-f76c-41d4-9f95-a1347dadfb76n%40googlegroups.com.

Timothy Stone

unread,
Mar 13, 2021, 10:32:32 AM3/13/21
to checkstyle
Thanks Roman. it had been a suspicion of mine that the GitLab CI/CD runner is at fault, but I couldn't point to it. i'll take a look at the CI configs you mention.

Question: is the use of the additional dependency, where I update the checkstyle dependency at runtime in my example correct? Meaning I provide the additional dependency containing my checkstyles declared in the configLocation. There is not really an example of this anywhere.

Timothy Stone

unread,
Mar 13, 2021, 10:45:44 AM3/13/21
to checkstyle
Roman,

Thanks! looks like my use of the dependency is permitted based on your cited example. Thank you! Now I have to meet with my DevOps team on Monday!

Tim

Roman Ivanov

unread,
Mar 13, 2021, 11:07:49 AM3/13/21
to Timothy Stone, checkstyle
here is example how we use plugin with extra jar (thirparty/custom checks)
it works.

Timothy Stone

unread,
Mar 15, 2021, 3:31:45 PM3/15/21
to checkstyle
Roman,

Thanks again for pointing me in a direction for resolution. I turned on mvn -X and found the issue in the CI/CD pipeline.

Where the maven-checkstyle-plugin allows for the runtime upgrade of checkstyle, the resolution of that dependency will quietly fall back to the defined repositories of the POM.

Unknown to me was that behind the scenes, maven was attempting to resolve the both the plugin runtime upgrade and the co.company.co-checkstyle:1.0.4:jar from pluginRepositories. The fallback behavior is to iterate over in the declared repositories and resolve through any declared mirrors.

I'm fairly certain checkstyle does not encounter the same problem as both checkstyle the plugin and com.github.sevntu-checkstyle:sevntu-checkstyle:1.38.0:jar are both available on central. If sevntu-checkstyle was not on central I think that the same problem would occur for the checkstyle project (and possibly has in the past).

My jar of checkstyle files is not on central. It is deployed to the gitlab package repository and the internal mirror for central could not find the gitlab repo for the project. Even providing a repository failed. Adding a pluginRepository addressed the issue immediately for the build.

As an aside, I am curious about the configLocation path in the checkstyle pom. With the plugin configuration the way it is, won't checkstyle load it from the classpath? That way only the plugin has to be upgraded with the sevntu, e.g., v1.38.0. A patch to the config directory version of the sevntu checkfile would not be necessary (if such a thing is performed today).

Thank you again!
Tim

Roman Ivanov

unread,
Mar 16, 2021, 10:30:46 AM3/16/21
to Timothy Stone, checkstyle
Hi Timothy,

there should no difference in runtime of checkstyle on where jars are taken (from which repo).
All of them dowloanded to local by any means and executed from local maven repo. 

config can be loaded from classpath, here is a way how to do this in exact approach
but we did load from classpath even before 8.41, read https://checkstyle.org/property_types.html#URI
there a lot of ways how to organize config location, you need to choose what best works for you.

thanks,
Roman Ivanov

Reply all
Reply to author
Forward
0 new messages