maven-shade-plugin reports: Error creating shaded jar: ...target/classes (Is a directory)
Asked Answered
V

2

9

When running a Maven build in eclipse using the m2eclipse tooling for a project that is configured for the Maven Shade Plugin, the build fails with the following error message:

Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.4.3:shade (default) on project xxx: Error creating shaded jar: /.../project/target/classes (Is a directory) -> [Help 1]

I tried different versions of the Shade plugin and tried with different Java versions (6,7,8). All lead to the same error.

Workaround:

The solution for this question provides a workaround: The error only occurs if the option Resolve Workspace Artifacts is selected. If this option is not selected, the build runs fine.

(However, this does not solve the problem since it is often very useful to build projects with enabled workspace resolution).

Vitrescent answered 21/6, 2016 at 11:2 Comment(3)
If just I could ... see Automatic Install of Maven Projects in Eclipse upon BuildVitrescent
What is the problem to download Maven itself and execute it from command line?Embarrass
My problem with that is as stated in the question linked in the previous comment. Essentially, since running mvn clean makes eclipse unusable for me doing builds, I resorted to disabling my script installing the artifacts and instead rely on the resolution within eclipse during development.Vitrescent
M
8

I found the issue and its resolution, the problem starts when trying to execute multiple phases in single command like mvn clean install -X test, if you run the single phase command like mvn test or mvn install its working. There is an issue with shaded plugin. These are the issues on apache site. https://issues.apache.org/jira/browse/MSHADE-295 and https://issues.apache.org/jira/browse/MSHADE-215 .

As per the issue, the shaded plugin wont work with multiple phases command. The plugin looks for the classes instead of jar with the name of jar and fails.

Hope this helps to someone.

Marshy answered 27/11, 2019 at 13:51 Comment(1)
Had the same exception, but during war and assembly plugins execution.Boehmer
T
4

it is often very useful to build projects with enabled workspace resolution

I used to think the same... Obviously, it was pretty useful to be able to build project right from another project located in the current workspace. However, I quickly entered a nightmare with Eclipse, m2eclipse and Maven.

On one hand, Maven is supposed to find the project dependencies in a repository (local, central ...). On the other hand, m2eclipse "lures" Maven making it believe that a project located in the Eclipse workspace is a dependency in a well known Maven place (ie a repository).

This m2eclipse magic works great in some cases but in others... it just plainly fails (maven shade plugin is an example). Did you also notice that the option Resolve Workspace Artifacts is not activated by default?

To escape the nigthmare, I found it useful to always fetch my projects dependencies from a repository. If my project A depends on another project B in my workspace, I just install B in the local repository (Right click on the project B, Run as > Maven install. That's all).

I can see three advantages with this workaround:

  • No more nightmares
  • No m2eclipse magic involved
  • Full standard and conventional Maven way honored

You can see this approach as a little freedom eater. If you still really want to go with the nifty option Resolve Workspace Artifacts, send an issue to the m2eclipse team. Don't forget to prepare a sample project reproducing the problem.

Toth answered 21/6, 2016 at 13:3 Comment(3)
I agree with this advice. It has many advantages to do things the 'clean' way and work with an up-to-date local or (even better) remote repository. Unfortunately, I have come across another problem which prevents me from going down this route (Question #35191737). At the moment building in eclipse with Resolve Workspace Artifacts is the best I could come up with ...Vitrescent
I'll see if maybe anyone has a solution and otherwise submit an issue!Vitrescent
I am having the same issue, trying to build shaded jar but it fails and giving the same error. I have added one dependency A into this shaded jar B. The jar A is of type proguard. Can anyone help me to solve this error. This error comes when I run the test module. Any help appreciated.Marshy

© 2022 - 2024 — McMap. All rights reserved.