3

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?

sixbitproxywax
  • 160
  • 1
  • 10
  • When you did override the plugin dependencies, did you explicitly set the scope on the override? – rec Jun 29 '15 at 19:11
  • I think so. I tried compile. I also tried it without the scope, I believe. EDIT: Setting the scope to runtime also seems to fail as it still looks for the tools.jar on Maven Central instead of Nexus. – sixbitproxywax Jun 29 '15 at 19:14
  • Overriding the dependency inside the tag sounds like a good approach. Of course just adding com.sun:tools to the tag won't help. You could try doing the override in the section instead of the regular section. – rec Jun 29 '15 at 19:18
  • Why won't just adding that to the dependencies help? – sixbitproxywax Jun 29 '15 at 19:33
  • are for your project's immediate dependencies. If you want to override the dependencies of a , you do it inside the tag. I'll make an example. – rec Jun 29 '15 at 20:00

1 Answers1

2

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.

Community
  • 1
  • 1
rec
  • 10,340
  • 3
  • 29
  • 43
  • Ah, Ok. I didn't understand what you meant earlier. Yes, *this* is what I tried and it did not work. It overrode the dependency, I think, but it won't search for the dependency in our Nexus. It just tries Maven Central and gives up. – sixbitproxywax Jun 29 '15 at 20:09
  • I extended the answer to mention how to configure plugin repositories. They need to be declared separately in the POM (or settings.xml). – rec Jun 29 '15 at 20:10
  • Ah! That could be the issue. Let me give it a shot. – sixbitproxywax Jun 29 '15 at 20:11
  • That seems to be working as expected, but I need to test a little more. Thanks! – sixbitproxywax Jun 29 '15 at 20:28
  • Cool. Please don't forget to accept the answer if it solves your issue . – rec Jun 30 '15 at 18:51