如何修复 MAVEN 中的 "Either artifact or artifactItems is required" 错误
How to fix "Either artifact or artifactItems is required" error in MAVEN
我的项目是一个非常简单的示例,因为我删除了您的所有代码以尝试通过 运行 命令 "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 条目。
根据你在做什么,如果你运行 mvn install
执行部分将自动执行,你不必运行 'mvn dependency:copy'
如果你想运行 mvn dependency:copy
分开,即在运行宁mvn package
之后,那么删除执行部分。现在不会自动拾取了,要加上mvn dependency: copy
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<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>
</plugin>
</plugins>
我的项目是一个非常简单的示例,因为我删除了您的所有代码以尝试通过 运行 命令 "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 条目。
根据你在做什么,如果你运行 mvn install
执行部分将自动执行,你不必运行 'mvn dependency:copy'
如果你想运行 mvn dependency:copy
分开,即在运行宁mvn package
之后,那么删除执行部分。现在不会自动拾取了,要加上mvn dependency: copy
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<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>
</plugin>
</plugins>