简体   繁体   English

Azure CI 管道无法构建 Java / Maven 解决方案与 2 个项目

[英]Azure CI Pipeline fails to build Java / Maven solution with 2 projects

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.我从课程中学习了基本的 Java / Maven 解决方案,我试图让它在 Azure CI 管道中工作。 The Java solution contains 2 projects; Java解决方案包含2个项目; each one has it's own pom file.每个人都有自己的 pom 文件。 I'm able to build and execute the tests from within Eclipse.我能够在 Eclipse 中构建和执行测试。 But when I try to use the solution in an Azure CI pipeline I've created it generates an error each time.但是,当我尝试在 Azure CI 管道中使用该解决方案时,我创建的它每次都会生成一个错误。

What do I need to change in the Azure pipeline file to get things to work?我需要在 Azure 管道文件中进行哪些更改才能正常工作? 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: Java解决方案信息:

This screenshot shows the overall Java solution structure and the location of the Azure pipeline file:此截图显示了整体 Java 解决方案结构和 Azure 管道文件的位置:

在此处输入图像描述

This screenshot shows how the two Java projects are structured:此屏幕截图显示了两个 Java 项目的结构:

在此处输入图像描述

This is the Azure pipeline file that I've created so far:这是我到目前为止创建的 Azure 管道文件:

 # Maven # Build your Java project and run tests with Apache Maven. # Add steps that analyze code, save build artifacts, deploy, and more: # https://docs.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'

The Maven pom file for the Tests project is:测试项目的 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>

The Maven pom file for the TestFramework project is: 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> <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>

Error is obviously related to TestFramework.错误显然与TestFramework有关。 You have to upload your TestFramework to custom repository or maven repository.您必须将您的 TestFramework 上传到自定义存储库或 maven 存储库。

Other choice is to build your TestFramework and put it your m2 repository of the container.其他选择是构建您的 TestFramework 并将其放入容器的 m2 存储库。 Then you can access TestFramework project然后你可以访问TestFramework项目

I think as other people have mentioned its because the build agent doesnt have the TestFramework artifact and cant pull it from anywhere.我认为正如其他人提到的那样,因为构建代理没有 TestFramework 工件并且不能从任何地方拉它。
The code for TestFramework might have been pulled into the build agent but it hasnt been built into a artifact. TestFramework 的代码可能已被拉入构建代理,但尚未构建到工件中。
You mention that you can run it from your local machine.你提到你可以从你的本地机器上运行它。 This is probably because youve built TestFramework at some point on that machine.这可能是因为您在那台机器上的某个时间点构建了 TestFramework。 You could look in the.m2 directory to check.您可以查看 .m2 目录进行检查。
As mentioned in the other comment you may want to publish the dependency or build/copy the artifact on the build agent.如另一条评论中所述,您可能希望发布依赖项或在构建代理上构建/复制工件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM