Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding Maven Plugin Dependency With System Scope

I have an environment where I need to have multiple JDKs installed to compile different projects. However, the aspectj-maven-plugin declares a dependency on com.sun:tools with the version set to the jre version and a systemPath set to JAVA_HOME.

Naturally, this will be wrong unless the JDK at JAVA_HOME is the intendend JDK for a given project.

Previously, I had some issues with our own code requiring tools.jar, so I resolved the problem by installing the tools.jar in our Nexus instance and adding a proper dependency to our pom files.

What I would like to do is force the aspectj-maven-plugin to use the tools.jar in our Nexus instance just like our own code now does instead of using a system scope dependency.

I tried to add a dependency on the plugin with a nested exclusion on the com.sun:tools dependency, but it did not seem to work.

I also tried to override the dependencies of the plugin by including a dependency on com.sun:tools:1.8 which can be found in our Nexus, but for some reason it only attempts to download this from Maven Central and ignores our Nexus instance.

I feel like I am close, but I am missing the precise incantation to get it to work.

Any ideas?

like image 909
sixbitproxywax Avatar asked Jan 22 '26 11:01

sixbitproxywax


1 Answers

Overriding the dependency of a plugin is done inside the <plugin> tag, e.g.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-plugin-plugin</artifactId>
      <version>3.3</version>
      <dependencies>
        <dependency>
          <groupId>com.sun</groupId>
          <artifactId>tools</artifactId>
          <version>1.7.0</version>
          <scope>runtime</scope>
        </dependency>
      </dependencies>
    </plugin>
 </plugins>
</build>

See also: https://maven.apache.org/pom.html#Plugins

I set the scope in the example above to runtime - the idea being that it should override the system scope defined for this dependency by the plugin's own POM. Mind I didn't test it.

Additionally, if you want plugins to be downloaded from your internal repository, you have to add a <pluginRepositories> section to your pom - a regular <repositories> section again only affects direct dependencies:

<pluginRepositories>
  <pluginRepository>
    <id>your-internal-nexus-id</id>
    <url>http://your.nexus.com/repository/path</url>
  </pluginRepository>
</pluginRepositories>

See also: https://maven.apache.org/pom.html#Plugin_Repositories

Maven may cache previous resolution failures. Make sure you try your next build with the parameter "-U" - or - that you purge the "lastUpdated" files from your repo.

like image 92
rec Avatar answered Jan 25 '26 13:01

rec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!