java - 如何修复MAVEN中的 "Either artifact or artifactItems is required"错误

标签 java maven package maven-dependency-plugin google-cloud-build

我的项目是一个非常简单的示例,因为我删除了所有代码以尝试通过运行命令“mvn dependency: copy -Dcopy.version = 0.0.1-SNAPSHOT”来查找问题。

重点是,我需要打包项目才能在 Google Cloud 上发布 .jar。

以下是 POM 的描述:

项目:app-java/pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.7.RELEASE</version>
    <relativePath />
</parent>

<modelVersion>4.0.0</modelVersion>

<groupId>br.com.example</groupId>
<artifactId>ticket</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>xxxx</name>
<url>xxxxxr</url>
<description>xxxxxx</description>

<properties>    
</properties>

<modules>
    <module>app</module>
</modules>

<profiles>
    <profile>
        <id>dev</id>
        <modules>
            <module>api</module>
        </modules>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <profile.id>dev</profile.id>
            <downloadSources>true</downloadSources>
            <downloadJavadocs>true</downloadJavadocs>
        </properties>
    </profile>
    <profile>
        <id>test</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <profile.id>test</profile.id>
            <downloadSources>true</downloadSources>
            <downloadJavadocs>true</downloadJavadocs>
        </properties>
    </profile>
    <profile>
        <id>all</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <profile.id>all</profile.id>
            <downloadSources>true</downloadSources>
            <downloadJavadocs>true</downloadJavadocs>
        </properties>
    </profile>
</profiles>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

项目:app/pom.xml

<parent>
    <groupId>br.com.example</groupId>
    <artifactId>ticket</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>app</artifactId>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.1.1</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>br.com.example</groupId>
                                <artifactId>app</artifactId>
                                <type>jar</type>
                                <overWrite>true</overWrite>
                                <outputDirectory>target/deploy</outputDirectory>
                                <destFileName>app.jar</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

执行的命令:

mvn -B versions:set -f app-java/pom.xml -DallowSnapshots=true -DnewVersion=0.0.1-SNAPSHOT -Pall
mvn clean -f app-java/pom.xml install -Pall -Dmaven.application.buildNumber=12
mvn dependency:copy -Dcopy.version=0.0.1-SNAPSHOT

回应:

app-java\app>mvn dependency:copy -Dcopy.version=0.0.1-SNAPSHOT
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< br.com.example:app >--------------------------
[INFO] Building app 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:3.1.1:copy (default-cli) @ app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.632 s
[INFO] Finished at: 2019-08-19T22:16:17-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy (default-cli) on project app: **Either artifact or artifactItems is required**  -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
mvn dependency:copy -Dcopy.version=0.0.1-SNAPSHOT

最佳答案

您配置了 dependency:copy-dependencies 的执行,但您还在命令行上调用了dependency:copy。这在 POM 中没有配置,因此会丢失 artifactItems 条目。

关于java - 如何修复MAVEN中的 "Either artifact or artifactItems is required"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57565785/

相关文章:

java - 将字符串中的数字相加

java - 语句 "int executeUpdate = prest.executeUpdate();"抛出 SQLException

java - Dropwizard 和 hive-jdbc 之间的不兼容

python - TypeError : unbound method __init__() . ...在重新打包后的单元测试期间

r - 无法在 R 中加载任何包(无法加载共享对象)

java - 在方法签名中将数组作为参数传递的替代语法是什么?

java - Wicket - 以优雅的方式检索 session 级别的 PageParameters

java - mvnw 权限在 travis 构建期间被拒绝错误

java.lang.ClassCastException : org. hibernate.action.DelayedPostInsertIdentifier 无法转换为 java.lang.Long

java - 是否可以使用 org.codehaus.mojo :build-helper-maven-plugin to bundle native dlls into a war file?