英文:
Azure CI Pipeline fails to build Java / Maven solution with 2 projects
问题
Summary:
我从课程中获取了一个基本的Java / Maven解决方案,并尝试在Azure CI流水线中使其工作。Java解决方案包含两个项目,每个项目都有自己的pom文件。我可以在Eclipse中构建并执行测试。但是,当我尝试在我创建的Azure CI流水线中使用该解决方案时,每次都会生成一个错误。
我需要在Azure流水线文件中进行哪些更改以使其正常工作?谢谢。
Error Message:
2020-05-15T15:31:58.1123350Z 从中央仓库下载: https://repo.maven.apache.org/maven2/junit/junit/4.12/junit-4.12.jar (315 kB at 3.6 MB/s)
2020-05-15T15:31:58.1124631Z [INFO] -----------------------------------------------------------------------
2020-05-15T15:31:58.1125092Z [INFO] BUILD FAILURE
2020-05-15T15:31:58.1125891Z [INFO] -----------------------------------------------------------------------
2020-05-15T15:31:58.1126382Z [INFO] 总时间: 1.621 秒
2020-05-15T15:31:58.1127089Z [INFO] 完成于: 2020-05-15T15:31:57Z
2020-05-15T15:31:58.1127980Z [INFO] -----------------------------------------------------------------------
2020-05-15T15:31:58.1129910Z [ERROR] 无法执行 Tests 项目的构建: 无法解析 com.pluralsight:Tests:jar:0.0.1-SNAPSHOT 的依赖项: 无法找到 artifact com.pluralsight:TestFramework:jar:0.0.1-SNAPSHOT -> [帮助 1]
2020-05-15T15:31:58.1130901Z [ERROR]
2020-05-15T15:31:58.1131330Z [ERROR] 要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。
2020-05-15T15:31:58.1132008Z [ERROR] 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。
2020-05-15T15:31:58.1132234Z [ERROR]
2020-05-15T15:31:58.1132574Z [ERROR] 有关错误和可能的解决方案的更多信息,请阅读以下文章:
2020-05-15T15:31:58.1133037Z [ERROR] [帮助 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
2020-05-15T15:31:58.1149156Z 未找到与 /home/vsts/work/1/s/**/surefire-reports/TEST-*.xml 匹配的测试结果文件,因此跳过发布 JUnit 测试结果。
2020-05-15T15:31:58.1177703Z ##[error] 构建失败。
2020-05-15T15:31:58.1207997Z ##[section]完成:Maven
Java解决方案信息:
此截图显示了整个Java解决方案结构以及Azure流水线文件的位置:
此截图显示了两个Java项目的结构:
这是我目前创建的Azure流水线文件:
# Maven
# 使用Apache Maven构建Java项目并运行测试。
# 添加分析代码、保存构建产物、部署等步骤:
# https://learn.microsoft.com/azure/devops/pipelines/languages/java
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Maven@3
inputs:
mavenPomFile: './Tests/pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'test'
Tests项目的Maven pom文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>Tests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.pluralsight</groupId>
<artifactId>TestFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
TestFramework项目的Maven pom文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>TestFramework</artifactId>
<version>0.0.1-SNAPSHOT</version
<details>
<summary>英文:</summary>
**Summary:**
I've taken a basic Java / Maven solution from a course and I'm trying to get it to work within an Azure CI pipeline. The Java solution contains 2 projects; each one has it's own pom file.
I'm able to build and execute the tests from within Eclipse.
But when I try to use the solution in an Azure CI pipeline I've created it generates an error each time.
What do I need to change in the Azure pipeline file to get things to work? Thanks.
**Error Message:**
2020-05-15T15:31:58.1123350Z Downloaded from central: https://repo.maven.apache.org/maven2/junit/junit/4.12/junit-4.12.jar (315 kB at 3.6 MB/s)
2020-05-15T15:31:58.1124631Z [INFO] ------------------------------------------------------------------------
2020-05-15T15:31:58.1125092Z [INFO] BUILD FAILURE
2020-05-15T15:31:58.1125891Z [INFO] ------------------------------------------------------------------------
2020-05-15T15:31:58.1126382Z [INFO] Total time: 1.621 s
2020-05-15T15:31:58.1127089Z [INFO] Finished at: 2020-05-15T15:31:57Z
2020-05-15T15:31:58.1127980Z [INFO] ------------------------------------------------------------------------
2020-05-15T15:31:58.1129910Z [ERROR] Failed to execute goal on project Tests: Could not resolve dependencies for project com.pluralsight:Tests:jar:0.0.1-SNAPSHOT: Could not find artifact com.pluralsight:TestFramework:jar:0.0.1-SNAPSHOT -> [Help 1]
2020-05-15T15:31:58.1130901Z [ERROR]
2020-05-15T15:31:58.1131330Z [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
2020-05-15T15:31:58.1132008Z [ERROR] Re-run Maven using the -X switch to enable full debug logging.
2020-05-15T15:31:58.1132234Z [ERROR]
2020-05-15T15:31:58.1132574Z [ERROR] For more information about the errors and possible solutions, please read the following articles:
2020-05-15T15:31:58.1133037Z [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
2020-05-15T15:31:58.1149156Z No test result files matching /home/vsts/work/1/s/**/surefire-reports/TEST-*.xml were found, so publishing JUnit test results is being skipped.
2020-05-15T15:31:58.1177703Z ##[error]Build failed.
2020-05-15T15:31:58.1207997Z ##[section]Finishing: Maven
**Java solution information:**
This screenshot shows the overall Java solution structure and the location of the Azure pipeline file:
[![enter image description here][1]][1]
This screenshot shows how the two Java projects are structured:
[![enter image description here][2]][2]
This is the Azure pipeline file that I've created so far:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/java
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Maven@3
inputs:
mavenPomFile: './Tests/pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'test'
<!-- end snippet -->
The Maven pom file for the Tests project is:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>Tests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.pluralsight</groupId>
<artifactId>TestFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
<!-- end snippet -->
The Maven pom file for the TestFramework project is:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>TestFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
<!-- end snippet -->
[1]: https://i.stack.imgur.com/v09QV.jpg
[2]: https://i.stack.imgur.com/X3Huj.jpg
</details>
# 答案1
**得分**: 0
错误明显与TestFramework有关。您必须将您的TestFramework上传到自定义仓库或Maven仓库。
另一个选择是构建您的TestFramework,并将其放入容器的m2仓库中。
然后您就可以访问TestFramework项目。
<details>
<summary>英文:</summary>
Error is obviously related to TestFramework. You have to upload your TestFramework to custom repository or maven repository.
Other choice is to build your TestFramework and put it your m2 repository of the container.
Then you can access TestFramework project
</details>
# 答案2
**得分**: 0
我认为正如其他人提到的那样,这是因为构建代理没有TestFramework构件,无法从任何地方获取它。
TestFramework的代码可能已被拉入构建代理,但尚未构建为构件。
你提到你可以从本地机器上运行它。这很可能是因为你曾经在该机器上构建过TestFramework。你可以查看.m2目录进行确认。
如在其他评论中所提到的,你可能希望发布这个依赖,或者在构建代理上构建/复制这个构件。
<details>
<summary>英文:</summary>
I think as other people have mentioned its because the build agent doesnt have the TestFramework artifact and cant pull it from anywhere.
The code for TestFramework might have been pulled into the build agent but it hasnt been built into a artifact.
You mention that you can run it from your local machine. This is probably because youve built TestFramework at some point on that machine. You could look in the .m2 directory to check.
As mentioned in the other comment you may want to publish the dependency or build/copy the artifact on the build agent.
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论