Incorrect build dependencies when maven module attaches multiple jars

Answered

Hi all,

I have a maven module A that deploys multiple jars using the maven build-helper plugin:

<execution>
<id>attach-jar1</id>
<phase>process-resources</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.outputDirectory}/myJar1.jar</file>
<type>jar</type>
<classifier>jar1</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
... same execution for myJar2
<execution>

Another module B defines a maven dependency on the attached jars:

<dependency>
<groupId>myGroup</groupId>
<artifactId>myJar1</artifactId>
<version>${project.version}</version>
<classifier>jar1</classifier>
</dependency>
... same with jar2

The project fails to build in IntelliJ (the maven build works fine) the compiler debugging shows that IntelliJ is using this classpath:
/Users/xxx/repos/bpmn/A/target/test-classes
/Users/xxx/repos/bpmn/A/target/classes
/Users/xxx/repos/bpmn/X/target/classes/myJar1.jar

There is no entry for myJar2 or any additional attached jar.

Franck
0
6 comments
Avatar
Yaroslav Bedrov

Hello,

Could you please share sample proejct example for investigation?

0
Avatar
Permanently deleted user

There you are. The maven build works fine, the IntelliJ build doesn't.

https://www.dropbox.com/s/y8zrrb4pi3xpiav/dependency-defect.zip?dl=0 

Franck

0
Avatar
Permanently deleted user

BTW looking at those ATTACHED-JAR libraries in Project Structure -> Project Settings -> Libraries shows that they have the wrong jar files listed (the first jar file is listed twice for each library).

Fixing that solves the problem, but only until the next POM update / Maven import.

Franck

0
Avatar
Yaroslav Bedrov

As a workarounf you could put adding under the same <execution>:

 

```

<configuration>
<artifacts>
<artifact>
<file>src/main/jars/commons-lang3-3.7.jar</file>
<type>jar</type>
<classifier>lang3</classifier>
</artifact>
<artifact>
<file>src/main/jars/commons-math-2.1.jar</file>
<type>jar</type>
<classifier>math</classifier>
</artifact>
</artifacts>
</configuration>

```
0
Avatar
Permanently deleted user

Nice, that works indeed... thanks!

0
Avatar
Yaroslav Bedrov

You are welcome!

0

Please sign in to leave a comment.