m2e shade eclipse “project main artifact does not exist”

非 Y 不嫁゛ 提交于 2019-12-09 07:13:08

问题


I'm trying to make a deployment package that bundles all the dependencies of my maven module that has dependencies to another maven project in eclipse.

I have this in my pom.xml

<modelVersion>4.0.0</modelVersion>
<groupId>com.my.proj</groupId>
<artifactId>AAA</artifactId>
<version>0.0.2-SNAPSHOT</version>
<name>btc</name>
<dependencies>
    <dependency>
        <groupId>com.another.proj</groupId>
        <artifactId>BBB</artifactId>
        <version>1.4-SNAPSHOT</version>
    </dependency>
</dependencies>

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.group.id.Launcher1</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

I use that "m2 Maven Build" in eclipse with the goal "org.apache.maven.plugins:maven-shade-plugin:shade" and the "Resolve Workspace artifacts" ticked.

It's failing with

--- maven-shade-plugin:1.6:shade (default-cli) @ AAA ---
[ERROR] The project main artifact does not exist. This could have the following
[ERROR] reasons:
[ERROR] - You have invoked the goal directly from the command line. This is not
[ERROR]   supported. Please add the goal to the default lifecycle via an
[ERROR]   <execution> element in your POM and use "mvn package" to have it run.
[ERROR] - You have bound the goal to a lifecycle phase before "package". Please
[ERROR]   remove this binding from your POM such that the goal will be run in
[ERROR]   the proper phase.

I ran out of idea at this point.


回答1:


[ERROR] The project main artifact does not exist. This could have the following

We were getting this problem recently. What resolved it for us was to not do mvn shade:shade but instead use:

mvn package

This does additional compilation and package work before running the shade plugin and so the main class was available on the classpath.




回答2:


The shade plugin is attempting to include the project's artifact in the shaded JAR. Since it doesn't exist (yet), you're getting this error. You either need to build/package the project artifact first (e.g., by attaching the shade goal to the package phase)

If you don't have any project artifact to include in the shaded JAR, you can add an excludes node to remove the project's artifact.

Here's an example:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>1.6</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <transformers>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>com.group.id.Launcher1</mainClass>
                        </transformer>
                    </transformers>
                    <excludes>
                        <exclude>com.my.proj:AAA</exclude>
                    </excludes>
                </configuration>
            </execution>
        </executions>
    </plugin>


来源:https://stackoverflow.com/questions/14494743/m2e-shade-eclipse-project-main-artifact-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!