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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…