What is the difference between maven.plugin.classpath and maven.runtime.classpath

醉酒当歌 提交于 2019-12-10 18:14:45

问题


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.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.


来源:https://stackoverflow.com/questions/34902288/what-is-the-difference-between-maven-plugin-classpath-and-maven-runtime-classpat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!