Maven多模块和源插件:如何保持项目的原始结构?

时间:2013-06-25 14:39:57

标签: maven pom.xml

我遇到Maven和Maven Source Plugin的问题,即生成的zip文件(和*-sources.jar文件)的结构与原始结构不同。这使得人们很难再次修改我们的源代码。因此,我想获得与原始版本相同的结构。

下面我将简要介绍项目的原始结构,zip文件的结构和*-sources.jar文件的结构。之后我将介绍两个pom.xml文件,父pom和其中一个模块。我要求的基本上是一种方法,如何将主pom.xml添加到zip文件并保留模块的结构(例如,eismassim-> src-> main)。当然我可以添加一个完成任务的bash脚本,但我认为有一个我不知道的通用解决方案。

让我先从整体描述开始:我在Maven中有一个具有以下结构的多模块项目:

.
|-- dep.xml
|-- pom.xml
|-- documents
|-- eismassim
|   |-- dep.xml
|   |-- pom.xml
|   `-- src
|       |-- main
|       |   `-- java
|       `-- test
|           `-- java
|-- javaagents
|   |-- dep.xml
|   |-- pom.xml
|   |-- scripts
|   `-- src
|       |-- main
|       |   `-- java
|       `-- test
|           `-- java
|-- massim
|   |-- dep.xml
|   |-- pom.xml
|   |-- scripts
|   `-- src
|       `-- main
|           |-- java
|           `-- resources
|-- webapp
|   |-- pom.xml
|   |-- scripts
|   |-- src
|   |   `-- main
|   |       |-- java
|   |       |-- resources
|   |       `-- webapp

生成的zip文件massim-2013-1.0-bin.zip具有以下结构:

.
|-- massim-2013-1.0
|   |-- CHANGELOG
|   |-- documents
|   |-- eismassim
|   |   `-- target
|   |       |-- dependency
|   |       |   |-- eis-0.3.jar
|   |       |   `-- junit-4.8.2.jar
|   |       |-- eismassim-2.1.jar
|   |       |-- eismassim-2.1-javadoc.jar
|   |       `-- eismassim-2.1-sources.jar
|   |-- javaagents
|   |   |-- scripts
|   |   `-- target
|   |       |-- dependency
|   |       |   |-- apltk-0.1.jar
|   |       |   |-- eis-0.3.jar
|   |       |   |-- eismassim-2.1.jar
|   |       |   `-- junit-4.8.2.jar
|   |       |-- javaagents-2.1.jar
|   |       |-- javaagents-2.1-javadoc.jar
|   |       `-- javaagents-2.1-sources.jar
|   |-- massim
|   |   |-- scripts
|   |   `-- target
|   |       |-- agentcontest-2013-1.0.jar
|   |       |-- agentcontest-2013-1.0-javadoc.jar
|   |       |-- agentcontest-2013-1.0-sources.jar
|   |       `-- dependency
|   |           |-- appframework-1.03.jar
|   `-- webapp
|       |-- scripts
|       |-- target
|       |   |-- massim-javadoc.jar
|       |   |-- massim-sources.jar
|       |   `-- massim.war

第三,eismassim-2.1-sources.jar

的结构
.
|-- massim
|   |-- App.java
|   |-- eis
|   `-- eismassim
|       |-- connection
|       |-- CowboysEntity.java
|       |-- Entity.java
|-- META-INF
|   `-- MANIFEST.MF
`-- pom.xml

解压缩jar文件后执行mvn package会导致空包。所以我必须再次为每个模块创建src->main->java并将文件移动到正确的位置或手动修改pom.xml。有可能解决这个问题吗?

父pom文件:

<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>massim</groupId>
  <artifactId>massim</artifactId>
  <version>2013-1.0</version>
  <packaging>pom</packaging>

  <name>MAPC Package</name>
  <url>http://multiagentcontest.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <modules>
    <module>massim</module>
    <module>eismassim</module>
    <module>javaagents</module>
    <module>webapp</module>
  </modules>

<build>
   <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
          <execution>
            <id>auto-clean</id>
            <phase>initialize</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
     <plugin>
       <artifactId>maven-assembly-plugin</artifactId>
       <executions>
         <execution>
           <goals>
             <goal>attached</goal>
           </goals>
           <phase>package</phase>
         </execution>
       </executions>
       <configuration>
         <descriptor>dep.xml</descriptor>
       </configuration>
     </plugin>
</plugins>
</build>

</project>

对于eismassim:

<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>massim</groupId>
  <artifactId>eismassim</artifactId>
  <version>2.1</version>
  <packaging>jar</packaging>

  <name>EISMASSim</name>
  <url>http://multiagentcontest.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>apleis</groupId>
      <artifactId>eis</artifactId>
      <version>0.3</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <archive>
            <manifestEntries>
              <Main-Class>massim.eismassim.EnvironmentInterface</Main-Class>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.2.1</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      <configuration>
        <includePom>true</includePom>
      </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.9</version>

        <configuration>
          <quiet>true</quiet>
        </configuration>
        <executions>
          <execution>
            <id>attach-javadocs</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
         <artifactId>wagon-ssh-external</artifactId>
         <version>1.0-beta-6</version>
      </extension>
    </extensions>
  </build>

</project>

感谢您的帮助。

0 个答案:

没有答案