【发布时间】:2016-05-05 03:53:33
【问题描述】:
我正在尝试使用 maven 着色器插件构建一个胖罐。我会在修复 maven 和破坏 IntelliJ 构建的过程中绕圈子,反之亦然。
我的项目如下(我省略了插件部分,其中包含着色器插件):
- module-a - 主项目模块,包含主类
- module-b - 模块,由 A 使用
- module-c - 模块,由 A 使用
模块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 的 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 上执行目标:无法解析 项目 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 -> [帮助 1]
我意识到我可能搞砸了这些 pom,试图使用依赖项与模块引用,但是 在 pom 文件中引用本地模块的正确方法是什么,而无需安装存储库中的模块?
我读到我应该创建一个以 module-a 作为父级的第四个父级项目,并使用该项目来创建阴影 jar,但即使使用这种方法,我也无法让它在同一个项目,它只解析 repo 模块。
【问题讨论】:
-
看起来你的依赖列表中有依赖于自身的模块 A。在模块 A 的 pom 中查看您的第一个依赖项的 artifactId——它是“module-a”。我认为应该是“module-c”?
-
是的,你是对的,我在简化发布时搞砸了。我更正了帖子,谢谢。