5

Maven recognizes 4 classpaths:

  • maven.compile.classpath: Classes and jars which need to be on classpath when compiling your source codes. So basically for maven-compiler-plugin

  • maven.test.classpath: Classes and jars which need to be on classpath when running unit tests or integration tests

  • maven.runtime.classpath: I understood that maven.runtime.classpath contains jars and classes maven itself needs to run.

  • maven.plugin.classpath: I understood that this classpath is pass to maven plugin when the plugin runs it's own JVM

Questions:

  • Am I right?
  • Is plugin superset of compile classpath?
  • Is test superset of compile classpath?
  • When plugin runs it's own JVM - what is the classpath passed to it?
  • Is there any documentation on this?
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Martin Tlachač
  • 379
  • 4
  • 17

1 Answers1

4

Actually, you have it wrong, but I couldn't find any documentation stating this explicitly.

Those 4 properties are defined by the maven-antrun-plugin and are not part of Maven itself. From Referencing the Maven Classpaths:

You can also use these classpath references:

  • maven.compile.classpath
  • maven.runtime.classpath
  • maven.test.classpath
  • maven.plugin.classpath

This plugin creates those 4 properties so that Ant tasks can refer to them. You'll find where those properties are created if you take a look at the source code, copied here for reference

Path p = new Path( antProject );
p.setPath( StringUtils.join( mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator ) );

/* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */
antProject.addReference( "maven.dependency.classpath", p );
antProject.addReference( "maven.compile.classpath", p );

p = new Path( antProject );
p.setPath( StringUtils.join( mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator ) );
antProject.addReference( "maven.runtime.classpath", p );

p = new Path( antProject );
p.setPath( StringUtils.join( mavenProject.getTestClasspathElements().iterator(), File.pathSeparator) );
antProject.addReference( "maven.test.classpath", p );

/* set maven.plugin.classpath with plugin dependencies */
antProject.addReference( "maven.plugin.classpath", getPathFromArtifacts( pluginArtifacts, antProject ) );

By analyzing this code, it is possible to conclude that:

  • maven.compile.classpath corresponds to elements of the classpath that are of scope compile.
  • maven.runtime.classpath corresponds to elements of the classpath that are of scope runtime.
  • maven.test.classpath corresponds to elements of the classpath that are of scope test.
  • maven.plugin.classpath corresponds to the dependencies of the maven-antrun-plugin itself.
Peter Hall
  • 53,120
  • 14
  • 139
  • 204
Tunaki
  • 132,869
  • 46
  • 340
  • 423