提问者:小点点

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


我试图建立一个胖jar与他maven着色器插件。我要在圈子里修复maven和打破IntelliJ构建,反之亦然。

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

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

模块A pom:

http://maven.apache.org/xsd/maven-4.0.0.xsd"

    <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 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>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我得到:

[错误]无法在项目module-a上执行目标:无法解析项目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-

我意识到我可能搞砸了这些pom,试图玩依赖与模块引用,但是在pom文件中引用本地模块的正确方法是什么,而不必在存储库中安装模块?

我读到我应该创建第四个父项目,其中模块a作为父项目,并使用该项目创建阴影jar,但即使使用这种方法,我也无法让它在同一个项目中定位模块,它只解析repo模块。


共1个答案

匿名用户

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

module-a的pom的这一部分反映了它是module-b和module-c的父级,但相反,您的module-b和c缺少

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

只是一个理解,你的模块的pom应该包括那些你可能想用作相同库的依赖项。所以我希望你想在你的module-a上使用来自module-b/c的一些代码来将它们包含在你的pom依赖项中。

或者您可能想从module-a中删除这些行

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

考虑到所有模块在层次结构方面是相互独立的。