m2e阴影蚀"项目主要工件不存在"

rom*_*run 2 eclipse maven-2 m2e maven-shade-plugin

我正在尝试创建一个部署包,它将我的maven模块的所有依赖项捆绑到eclipse中的另一个maven项目.

我在我的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>
Run Code Online (Sandbox Code Playgroud)

我在eclipse中使用"m2 Maven Build",其目标是"org.apache.maven.plugins:maven-shade-plugin:shade"和"Resolve Workspace artifacts".

它失败了

--- 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.
Run Code Online (Sandbox Code Playgroud)

我此时已经没想完了.

Gra*_*ray 11

[错误]项目主要工件不存在.这可能有以下几点

我们最近遇到了这个问题.什么解决这对我们来说是没有mvn shade:shade,而是使用:

mvn package
Run Code Online (Sandbox Code Playgroud)

运行shade插件之前,这会进行额外的编译和打包工作,因此类路径上可以使用主类.


Tho*_*lor 7

阴影插件试图将项目的工件包含在阴影 JAR 中。由于它不存在(还),您会收到此错误。您需要先构建/打包项目工件(例如,通过将阴影目标附加到打包阶段)

如果您没有任何项目工件要包含在阴影 JAR 中,您可以添加一个excludes节点来移除项目的工件。

下面是一个例子:

<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>
Run Code Online (Sandbox Code Playgroud)