Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

Force Maven Lifecycle for Project Module

I am using org.apache.maven.plugins:maven-shade-plugin:3.2.4 to create a single JAR file that contains all of my (multi-module) project's core dependencies. From there, I make this module a dependency for all my other modules. This allows me to have one place for all of the core dependencies to be defined and only one shade plugin relocation configuration, instead of having to copy & paste the same shade plugin information into each module that all want to shade dependencies in the same way.

However, the problem is that the shade-plugin does not run before the package phase. So, if I run just mvn test the project fails to compile because these core dependencies are not gathered, shaded, relocated, until the package phase.

Is there a way that I can define in the POM a way that will always run this one module to the package phase regardless of the mvn phase specified at the top-level directory?

FYI: Guava 27.0-jre

<?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/maven-v4_0_0.xsd">
  <parent>
    <artifactId>app</artifactId>
    <groupId>org.my.app</groupId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>app-thirdparty</artifactId>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <relocations>
                <relocation>
                  <pattern>com.google</pattern>
                  <shadedPattern>org.my.app.thirdparty.com.google</shadedPattern>
                </relocation>
                <relocation>
                  <pattern>org.checkerframework</pattern>
                  <shadedPattern>org.my.app.thirdparty.org.checkerframework</shadedPattern>
                </relocation>
                <relocation>
                  <pattern>org.codehaus</pattern>
                  <shadedPattern>org.my.app.thirdparty.org.codehaus</shadedPattern>
                </relocation>
              </relocations>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
question from:https://stackoverflow.com/questions/66049754/force-maven-lifecycle-for-project-module

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...