java 使用默认构建插件代替maven shade

2ul0zpep  于 2023-03-06  发布在  Java
关注(0)|答案(1)|浏览(139)

我想使用maven创建两个模块的jar文件(每个都是一个单独的fat jar),这取决于第三个模块。我的问题是如果我使用“mvn包”,它不使用maven-shade-plugin,而是使用maven-jar-plugin:2.4:jar(default-jar)。即使它没有定义这样做。为什么?
母项目POM:

<groupId>com.firstproject.myapp</groupId>
  <artifactId>parent-project</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>Player Communication Parent Project</name>

  <modules>
    <module>simple-message</module>
    <module>simple-client</module>
    <module>simple-server</module>
  </modules>

  <properties>
      <maven.compiler.source>17</maven.compiler.source>
      <maven.compiler.target>17</maven.compiler.target>
  </properties>

<dependencies>

</dependencies>

<build>
 
</build>

</project>

简单客户端POM

<build>
    <finalName>Server</finalName>
    <pluginManagement>
      <plugins>
        <!-- Maven JAR Plugin for TCPServer -->
      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.4.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>com.firstproject.myapp.AppServer</mainClass>
                        </transformer>
                    </transformers>
                        <minimizeJar>false</minimizeJar>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <dependencyReducedPomLocation>
                            ${java.io.tmpdir}/dependency-reduced-pom.xml
                        </dependencyReducedPomLocation>
                        <relocations>
                            <relocation>
                                <pattern>com.firstproject.myapp</pattern>
                                <shadedPattern>hidden.coyote</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>
              </execution>
            </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
cnwbcb6i

cnwbcb6i1#

maven-jar-plugin由生命周期隐式定义,但这不是您的问题。
您的问题是将插件定义放入<pluginManagement>,这意味着插件实际上没有运行,您需要将其移到<build><plugins>

相关问题