Maven (eclipse) use shaded jar instead of original jar

Unknown :

I have a project, where the packages will be relocated (shaded jar)

pom.xml:

<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>

  <artifactId>artifact-child</artifactId>
  <name>artifact-child</name>

  <parent>
    <groupId>group</groupId>
    <artifactId>artifact</artifactId>
    <version>${revision}</version>
  </parent>

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

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.2</version>

        <configuration>
          <!--  <shadedArtifactAttached>true</shadedArtifactAttached> -->

          <relocations>
            <reloaction>
              <pattern>example</pattern>
              <shadedPattern>${super-package}.example</shadedPattern>
            </reloaction>
          </relocations>          
        </configuration>

        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>  
    </plugins>
  </build>
</project>

And I have a second project, which need the shaded jar at runtime.

pom.xml:

<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>testversion</groupId>
  <artifactId>testv</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>testv</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>group</groupId>
      <artifactId>artifact-child</artifactId>
      <version>0.0.1</version>
      <classifier>shaded</classifier>
    </dependency>
  </dependencies>
</project>

My question:

Eclipse find the other project in his workspace and use directly the source code.

For example: I must write import example.myclass instead of import org.example.myclass.

In some cases, this can be a problem. Is it possible to say, what maven or eclipse should use the "shaded jar" instead of the original source code?

Must I create a online repository, so maven can only download the shaded jar?



I found two other stackoverflow posts (with no result):

Maven Eclipse multi-module shaded dependency

How to install shaded jar instead of the original jar

JF Meier :

If the shaded jar is your dependendy, you just reference the classes/packages as they are defined in the shaded jar.

If Eclipse shows an error, Eclipse is wrong (which is often the case). First of all, try to build your project with something like clean verify. Then you see whether you really have errors (or if Eclipse made them up).

If Eclipse errors bother you, try ALT+F5.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=21637&siteId=1