问题
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?
回答1:
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.classpathmaven.runtime.classpathmaven.test.classpathmaven.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.classpathcorresponds to elements of the classpath that are of scopecompile.maven.runtime.classpathcorresponds to elements of the classpath that are of scoperuntime.maven.test.classpathcorresponds to elements of the classpath that are of scopetest.maven.plugin.classpathcorresponds to the dependencies of themaven-antrun-pluginitself.
来源:https://stackoverflow.com/questions/34902288/what-is-the-difference-between-maven-plugin-classpath-and-maven-runtime-classpat