2016-01-27 41 views
0

我想與他的Maven着色器插件構建一個胖罐子。我正在修復maven並打破IntelliJ構建,反之亦然。IntelliJ和Maven的着色器插件與多個模塊

我的項目是如下(我離開了插件的部分,包含着色器插件):

  1. 模塊一 - 主體工程模塊,包含主類
  2. 模塊-B - 模塊,使用由A
  3. 模塊-C - 模塊,由A

模塊中使用的聚甲醛:

http://maven.apache.org/xsd/maven-4.0.0.xsd「> 4.0.0

<groupId>com.my</groupId> 
    <artifactId>module-a</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <modules> 
     <module>../module-b</module> 
     <module>../module-c</module> 
    </modules> 

    <dependencies> 
     <dependency> 
      <groupId>com.my</groupId> 
      <artifactId>module-b</artifactId> 
      <version>1.0-SNAPSHOT</version> 
     </dependency> 

     <dependency> 
      <groupId>com.my</groupId> 
      <artifactId>module-c</artifactId> 
      <version>1.0-SNAPSHOT</version> 
     </dependency> 

     <dependency> 
      <groupId>org.clapper</groupId> 
      <artifactId>grizzled-slf4j_2.11</artifactId> 
      <version>1.0.2</version> 
     </dependency> 

     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>1.7.7</version> 
     </dependency> 

     <dependency> 
      <groupId>com.typesafe.akka</groupId> 
      <artifactId>akka-http-experimental_2.11</artifactId> 
      <version>2.0.3</version> 
     </dependency> 

     <dependency> 
      <groupId>com.typesafe.akka</groupId> 
      <artifactId>akka-http-core-experimental_2.11</artifactId> 
      <version>2.0.3</version> 
     </dependency> 

     <dependency> 
      <groupId>com.typesafe.akka</groupId> 
      <artifactId>akka-stream-experimental_2.11</artifactId> 
      <version>2.0.3</version> 
     </dependency> 

     <dependency> 
      <groupId>net.ceedubs</groupId> 
      <artifactId>ficus_2.11</artifactId> 
      <version>1.1.2</version> 
     </dependency> 

     <dependency> 
      <groupId>com.typesafe</groupId> 
      <artifactId>config</artifactId> 
      <version>1.3.0</version> 
     </dependency> 

     <dependency> 
      <groupId>ch.qos.logback</groupId> 
      <artifactId>logback-classic</artifactId> 
      <version>1.1.3</version> 
     </dependency> 

     <dependency> 
      <groupId>com.typesafe.akka</groupId> 
      <artifactId>akka-actor_2.11</artifactId> 
      <version>2.4.1</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.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <version>1.5</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
        <configuration> 
         <shadedArtifactAttached>true</shadedArtifactAttached> 
         <shadedClassifierName>allinone</shadedClassifierName> 
         <artifactSet> 
          <includes> 
           <include>*:*</include> 
          </includes> 
         </artifactSet> 
         <transformers> 
          <transformer 
            implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
           <resource>reference.conf</resource> 
          </transformer> 
          <transformer 
            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
           <manifestEntries> 
            <Main-Class>com.my.Service</Main-Class> 
           </manifestEntries> 
          </transformer> 
         </transformers> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

     </plugins> 
    </build> 

</project> 

模塊B和C POMS是相似的(除模塊名稱)

<?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>com.my</groupId> 
    <artifactId>module-b</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 


    <dependencies> 
     <dependency> 
      <groupId>com.typesafe.akka</groupId> 
      <artifactId>akka-actor_2.11</artifactId> 
      <version>2.4.1</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.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

所有模塊位於相同級別的同一目錄中。儘管我可以通過IntelliJ構建,但我無法通過maven構建模塊,因爲它找不到模塊-b和-c。所以一般來說,我不能構建引用本地項目的任何東西,因爲Maven不會找到它們。如果我在IDE或命令行中嘗試它,無所謂。

建築模塊,一個我得到:

[錯誤]未能就項目的執行目標模塊一:無法解析 依賴項目com.my:module-a:pom:1.0-SNAPSHOT : 以下工件無法解析: com.my:module-b:jar:1.0-SNAPSHOT,com.my:module-c:jar:1.0-SNAPSHOT: 無法找到工件com.my:module- c:jar:1.0-SNAPSHOT - > [Help 1]

我意識到我可能搞砸了這些poms,嘗試玩與依賴關係與模塊引用,但什麼是正確的方式來引用一個本地模塊在pom文件,而不必將模塊安裝在存儲庫?

我讀到我應該創建一個第四個父項目,其中有一個模塊a作爲父項,並使用該項目創建陰影的jar,但即使採用這種方法,我也無法使其找到模塊同一個項目,它只解析回購模塊。

+0

它看起來像你有模塊A取決於你自己的依賴列表。看看模塊A的pom中的第一個依賴關係的artifactId - 它是「模塊-a」。我認爲它應該是「模塊-C」? – adammtlx

+0

是的你是對的,當我簡化發佈時,我搞砸了。我糾正了這個帖子,謝謝。 –

回答

0
<packaging>pom</packaging> 
    <modules> 
     <module>../module-b</module> 
     <module>../module-c</module> 
    </modules> 

你的模塊,一個的POM,這部分反映了它的模塊B和模塊C,但反之你的模塊,b和c缺少

<parent> 
     <groupId>com.my</groupId> 
     <artifactId>module-a</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 

只是一個認識父,你的模塊的pom應該包含你可能想用作庫的依賴關係。所以我希望你想使用模塊-b/c中的一些代碼來將它們包含在pom依賴關係中。


或者你可能想從您module-a

<modules> 
     <module>../module-b</module> 
     <module>../module-c</module> 
    </modules> 

考慮所有的模塊刪除這些行層次結構方面是相互獨立的。

+0

謝謝。因此,如果我正確讀取,只需將塊添加到模塊-b和-c應該可以工作?不幸的是我錯過了一些東西,因爲我最終得到了循環引用。我完全不明白。該消息被重複兩次(使用交換的模塊順序):反應器中的項目包含一個循環引用:'Vertex {label ='com.my:project-c:1.0-SNAPSHOT'}' 和'Vertex {label ='com.my:project-b:1.0-SNAPSHOT'}'介紹在圖中循環com.my:project-b:1.0-SNAPSHOT - > com.my:project-c:1.0-SNAPSHOT - > com.my:project-b:1.0-SNAPSHOT - > [Help 1] –

+0

你可以用 – nullpointer

+0

這個問題中的每個模塊的完整pom進行更新嗎?沒有添加父塊,這也會破壞IDE的構建。謝謝你的幫助! –