我的项目是一个非常简单的示例,因为我删除了所有代码以尝试通过运行命令“ mvn依赖项: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
答案 0 :(得分:1)
您配置了dependency:copy-dependencies
的执行,但是您也可以在命令行上调用dependency:copy
。在POM中没有配置,因此错过了artifactItems条目。
答案 1 :(得分:0)
取决于你在做什么,如果你运行 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>