具有多个模块的IntelliJ和Maven着色器插件

时间:2016-01-27 23:31:28

标签: maven pom.xml

我正在尝试使用maven着色器插件构建一个胖罐。我正在修改maven和打破IntelliJ构建的圈子,反之亦然。

我的项目如下(我省略了插件部分,其中包含着色器插件):

  1. module-a - 主项目模块,包含主类
  2. module-b - 模块,由A
  3. 使用
  4. module-c - 模块,由A
  5. 使用

    模块A pom:

        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构建模块-a,因为它找不到模块-b和-c。所以一般来说,我不能构建任何引用本地项目的东西,因为Maven不会找到它们。如果我在IDE中或从命令行中尝试它无关紧要。

    构建模块-a我得到:

      

    [错误]无法在项目模块上执行目标-a:无法解决   项目的依赖项com.my:module-a:pom:1.0-SNAPSHOT:The   以下工件无法解决:   com.my:module-b:jar:1.0-SNAPSHOT,com.my:module-c:jar:1.0-SNAPSHOT:   找不到工件com.my:module-c:jar:1.0-SNAPSHOT - &gt; [帮助1]

    我意识到我可能搞砸了这些poms,尝试使用依赖项和模块引用,但是在pom文件中引用本地模块的正确方法是什么,而无需安装存储库中的模块?

    我读到我应该创建第四个父项目,其中module-a作为父项,并使用该项目创建着色jar,但即使采用这种方法,我也无法在其中找到模块同一个项目,它只解析回购模块。

0 个答案:

没有答案