我真的想要做到这一点:
令人惊讶的是,在找到一个明确的例子后我想要Maven做什么......我仍然无法让它发挥作用。
从命令行,我可以运行... mvn -Dmdep.outputFile = classpath.txt依赖项:build-classpath ...确实会生成一个名为classpath.txt的文件,其中包含我想要的信息。
我希望能够发出像“mvn compile”这样的命令,并将此classpath.txt文件的生成作为该进程的一部分。上面链接中提供的示例将其与generate-sources相关联,根据我的理解,这应该足够了。
当使用下面的pom片段执行像“mvn compile”这样的命令时,似乎没有任何关于构建类路径目标的命令。
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>build-classpath</id>
<phase>generate-sources</phase>
<goals>
<goal>build-classpath</goal>
</goals>
<configuration>
<outputFile>myfile.txt</outputFile>
<mdep.outputFile>myFile1.txt</mdep.outputFile>
<ihavenoidea>whatgoeshere</ihavenoidea>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
以下是我的最终结果:
$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building someproj 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ someproj ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ someproj ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.600s
[INFO] Finished at: Fri Jan 31 14:05:29 CST 2014
[INFO] Final Memory: 9M/156M
[INFO] ------------------------------------------------------------------------
$ ls
bin html log pom.xml resources sql src target test-output wwwroot
答案 0 :(得分:1)
您的插件定义位于<pluginManagement>
内,这意味着当您在pom中声明该插件的“真实”执行时,该pom将此pom作为父级(或此pom本身),它将使用该配置
当通过同一个全局项目中的多个模块对多个执行应用通用配置时,使用<pluginManagement>
通常是个好主意。
在这里,我个人会将编译器插件保留在<pluginManagement>
中,因为您可能总是希望将插件配置为这样,但是我会将依赖插件移到<plugins>
部分内部(外部) <pluginManagement>
部分,是的,这可能会让人感到困惑......)
答案 1 :(得分:0)
您可能会将<pluginManagement>
视为一种模板。它通常在父POM中用于定义通用配置。只有<build><plugins>
中的插件才会包含在构建中。
也就是说,Maven根据包装类型做了一些“魔术”。我回答了类似的问题here。