Maven Shading Error: Access is Denied

2019-02-17 20:42发布

问题:

Now, I have already seen this question, however it doesn't appear anything is using my target folder.

What's going on, is when I compile it fails and shows me this error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.3:shade (default) on project FooProject: Error creating shaded jar: Failed to analyze class dependencies: C:\Users\paul_000\Documents\FooCore\target\classes (Access is denied) -> [Help 1]

I'm not quite sure exactly why this happens, as it doesn't happen on my normal computer.

EDIT: I forgot to mention, the jar I am shading does not exist on a repository. I just compile it locally (clean install). As well, here's what I use to shade:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <configuration>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <minimizeJar>true</minimizeJar>
            </configuration>
        </execution>
    </executions>
</plugin>

回答1:

You can face this error, if you're compiling from Eclipse with m2e plugin.

The workaround is to uncheck Resolve Workspace artifacts in the Maven Run Configuration.



回答2:

I am using Eclipse Spring with the maven plugin. I was seeing a similar error in the logs:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.3:shade (default) on project lds_ws_framework: Error creating shaded jar: C:\Users\fritchd\Documents\autoaction_archivetkitproject\target\classes (Access is denied) -> [Help 1]

I had recently updated my projects to use the maven-shade-plugin 2.3 from a different maven build process. I noticed I had a lot of artifacts from the previous process in the \target folder. So I tried just deleting all files under the \target directory for that project. When I reran the build, I didn't see the error.



回答3:

Use the artifactSet option of maven-shade-plugin

For whatever reason this way Eclipse does not produce the "Access Denied" error