2016-07-26 219 views
1

我知道你使用程序集插件來做這件事,而且我嘗試了許多描述符,但他們不工作。我無法理解錯誤信息的含義。maven在多模塊項目中建立依賴關係的jar

項目架構:

---sti (parent project containing a pom.xml) 
-----sti-any23 
-----sti-common-util 
-----sti-kbsearch 
-----sti-websearch 
-----sti-main 

STI是一個聚合的項目。模塊sti-main取決於所有其他四個模塊。

父項目的pom.xml的樣子:

<?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>....</groupId> 
    <artifactId>sti</artifactId> 
    <version>1.0alpha</version> 
    <packaging>pom</packaging> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     <maven-install-plugin.version>2.5.2</maven-install-plugin.version> 
     <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> 
     <maven-source-plugin.version>2.2.1</maven-source-plugin.version> 
     <exec-maven-plugin.version>1.4.0</exec-maven-plugin.version> 
     <maven-shade-plugin.version>2.3</maven-shade-plugin.version> 
    </properties>   
    <modules> 
     <module>sti-any23</module> 
     <module>sti-common-util</module> 
     <module>sti-kbsearch</module> 
     <module>sti-websearch</module> 
     <module>sti-main</module> 
    </modules>    
    <build> 
     <defaultGoal>install</defaultGoal> 
     <plugins>     
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-source-plugin</artifactId> 
       <version>${maven-source-plugin.version}</version> 
       <executions> 
        <execution> 
         <id>attach-sources</id> 
         <phase>verify</phase> 
         <goals> 
          <goal>jar</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>${exec-maven-plugin.version}</version> 
       <configuration> 
        <mainClass/> 
       </configuration> 
      </plugin> 
      <plugin> 
       <inherited>true</inherited> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>${maven-compiler-plugin.version}</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
        <encoding>UTF-8</encoding> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <version>2.5.4</version> 
       <configuration> 
        <descriptorRefs> 
         <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
       </configuration> 
       <executions> 
        <execution> 
         <id>make-assembly</id> 
         <phase>package</phase> 
         <goals> 
          <goal>single</goal> 
         </goals> 
         <configuration> 
          <descriptors> 
           <descriptor>config/maven-assembly/module.xml</descriptor> 
          </descriptors> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 
    </build> 
</project> 

描述符 '配置/ Maven的組裝/ module.xml' 的樣子:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> 
    <!-- TODO: a jarjar format would be better --> 
    <id>alljars</id> 
    <formats> 
    <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <dependencySets> 
    <dependencySet> 
     <outputDirectory>/</outputDirectory> 
     <useProjectArtifact>true</useProjectArtifact> 
     <unpack>true</unpack> 
     <scope>runtime</scope> 
    </dependencySet> 
    </dependencySets> 
</assembly> 

的錯誤,我得到:

[WARNING] Cannot include project artifact: uk.ac.shef.dcs:sti:pom:1.0alpha; it doesn't have an associated file or directory. 
[INFO] ------------------------------------------------------------------------ 
[INFO] Reactor Summary: 
[INFO] 
[INFO] sti-any23 .......................................... SUCCESS [ 1.709 s] 
[INFO] sti-common-util .................................... SUCCESS [ 0.728 s] 
[INFO] sti-kbsearch ....................................... SUCCESS [ 1.213 s] 
[INFO] sti-websearch ...................................... SUCCESS [ 0.433 s] 
[INFO] sti-main ........................................... SUCCESS [ 2.855 s] 
[INFO] sti ................................................ FAILURE [ 0.389 s] 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 7.839 s 
[INFO] Finished at: 2016-07-26T19:50:53+01:00 
[INFO] Final Memory: 75M/505M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.5.4:single (make-assembly) on project sti: Failed to create assembly: Error creating assembly archive alljars: You must set at least one file. -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command 
[ERROR] mvn <goals> -rf :sti 

我也嘗試了很多其他描述符在stackoverflow上找到,但他們都沒有工作。我想我一定有一些基本的概念錯了,但我不知道它是什麼。

請提出任何建議。謝謝

回答

1

我從來沒有見過在父項目中使用assembly plugin。你的母模塊是<packaging>pom</packaging>。它的輸出只是一個pom文件。除POM外還有任何物理僞像輸出是沒有意義的。

在我看來,您應該將程序集插件聲明移至子模塊,並僅將其作爲此子模塊的一部分執行。所有其他項目都應聲明爲此模塊的依賴項,從這一點開始,您應構建程序集。

+0

是的。或者甚至有一個新的模塊,其目標是創建程序集。使用來自父級的'maven-assembly-plugin'可以用來組裝[模塊二進制文件](http://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-binary-inclusion- simple.html),但我也明顯喜歡在現有模塊或專用模塊內部執行此操作。 – Tunaki

+0

謝謝。我改變 'packaing' 到 '罐',刪除 '模塊' 塊和添加的塊 ' uk.ac.shef.dcs STI-主 1.0alpha '。它似乎在做伎倆。它是否正確? – Ziqi

+0

我同意@Tunaki我也喜歡專門的模塊來完成這項工作。 –

相關問題