Kal*_*sto 17 parent pom.xml maven
Maven需要一个父项目
<packaging>pom</packaging>
父pom.xml中的子句.安装这样的项目时,只有一个pom文件生成到maven存储库中.无论父项目是否具有任何Java代码,都不会生成Jar文件.这迫使我有额外的空父项目,这是过度的.从逻辑上讲,我的一些图书馆可能同时也是父母.
有没有办法为父项目生成pom和jar文件,而无需packaging在安装之间删除/添加子句?
noa*_*hlz 13
使用Maven Jar插件和Maven Build Helper.示例POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>test-${project.version}</file>
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
Maven构建结果:
mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- build-helper-maven-plugin:1.7:attach-artifact (attach-artifacts) @ test ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default) @ test ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ test ---
[INFO] Installing /home/username/projects/test/pom.xml to /home/username/.m2/repository/test/test/1.0/test-1.0.pom
[INFO] Installing /home/username/projects/test/test-1.0 to /home/username/.m2/repository/test/test/1.0/test-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.805s
[INFO] Finished at: Thu Sep 06 13:33:20 EDT 2012
[INFO] Final Memory: 4M/119M
[INFO] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
关于Maven实践的说明:
父模块通常用于定义所有子模块共同使用的依赖项和插件.它很少有自己的输出.您可能希望拥有一个"分发"子模块,该子模块聚合所有其他模块工件,而不是尝试在父模块中执行此操作.
| 归档时间: |
|
| 查看次数: |
13365 次 |
| 最近记录: |