0

I'm using maven-dependency-plugin to extract some classes from a big jar and add them to my project classes. Right no, there 2 jars, each build with a classifier: sources and helper. The sources jar has all java files. The helper jar has most of the classes (classes no java files) of complete dependency.

Since I need the missing classes, I would like to extract all java files from "sources"-classifier-jar to target/extracted/src instead of the classes from "helper"-classifier-jar to target/classes, and compile them. Since my project depends on the compiled classes I'm running the dependency-plugin during generate-sources-phase.

Does anybody have an idea how I could achieve this? What am I doing wrong? I have tried adding a source-directory (which would be the output directory of the dependency-plugin) with the compiler-plugin, but I can't build the project. It doesn't find the classes.

<plugin>
  <artifactId>mave-dependency-plugin>
  <executions>
    <execution>
      <configuration>
        <artifactItems>
          <artifactItem>
            <gropuId>...</groupId>
            <artifactId>...</artifactId>
            <version>1.0</version>
            <includes>
              com/acme/Bar.java
            </includes>
            <overWrite>false</overWrite>
            <type>jar</type>
          </artifactItem>
       </artifactItems>
       <outputDirectory>${project.build.directory}/extracted/src</outputDirectory>
      </configuration>
      <goals>
        <goal>unpack</goal>
      </goals>
      <id>unpack</id>
      <phase>generate-sources</phase>
    </execution>
  </executions>
</plugin>      
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>3.2.0</version>
  <executions>
     <execution>
     <id>add-source</id>
     <phase>generate-sources</phase>
     <goals>
        <goal>add-source</goal>
     </goals>
     <configuration>
       <sources>
        <source>${project.build.directory}/extracted/src</source>
       </sources>
     </configuration>
   </execution>
  </executions>
</plugin>

Somewhere in my project java classes I have a reference to Bar.class e.g.

import com.acme.Bar;

I would appreciate any helpful hint.

Rubén
  • 427
  • 1
  • 9
  • 23
  • 1
    Why are you trying to use an artifacts as source package and not consuming it via a dependency? – khmarbaise Jan 11 '21 at 15:56
  • this is a 3th-Party-library that is fully (spring) custom artifacts that are not configurable and do not fit for us. These libraries are not so clever delivered and we have no influence on their development. The Problem with getting the Sources is because, one of the libraries is a classified artifact containing only part of the classes we need. They are working on it to modularize they Code better. But since we need to go Forward with are implementation, we needed a Workaround till they are Ready. I got this running. With the Approach described above. – Rubén Jan 19 '21 at 12:05
  • Deploy them into a repository manager and consume them from there ...trying to build that way will fail... – khmarbaise Jan 19 '21 at 13:14
  • we got this working. We just extracted the classes and resources we needed and compiled them as normal Sources. – Rubén Jan 19 '21 at 15:18

0 Answers0