0

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

This screenshot shows how the two Java projects are structured:

enter image description here

This is the Azure pipeline file that I've created so far:

# 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'

The Maven pom file for the Tests project is:

<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:

<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>
  • Do you use any custom repository for your projects? Example : jfrog – Gurkan İlleez May 29 '20 at 17:10
  • The error says that TestFramework could not be resolved for Tests module as the same has to be deployed first – Arun May 29 '20 at 17:16
  • @Gurkanİlleez: I've used the regular Azure Git repo to host all of the code for the entire solution (that is both of java projects as shown in the screenshots above). – DarkLord_109 Jun 01 '20 at 15:12
  • @Arun: The pom file for the Tests project includes a dependency for the TestFramework project in it. At the moment my Azure pipeline file just points at the Tests project pom file. Would I need to update the Azure pipeline file to include entries for both the Tests and TestFramework projects then ? I expect it would go before the Tests project section then but wouldn't that defect the benefit of listing the TestFramework project dependency in the Tests project pom file? – DarkLord_109 Jun 01 '20 at 15:17
  • It looks like more of a typical maven issue, can the suggestions from [issue#1](https://stackoverflow.com/questions/4650460/maven-could-not-resolve-dependencies-artifacts-could-not-be-resolved) and [issue#2](https://stackoverflow.com/questions/24673671/mavenerror-failed-to-execute-goal-on-project-could-not-resolve-dependencies-in) make some help for you? – LoLance Jun 02 '20 at 07:20

2 Answers2

0

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

Gurkan İlleez
  • 1,503
  • 1
  • 10
  • 12
  • I currently have all of the solution code (both Java projects) uploaded into the Azure Git repo. In theory the CI pipeline should be able to see all of the code held in the Git repo for this solution already but sadly that is not the case just yet. Could you please clarify what you are suggesting as a result. Many thanks. – DarkLord_109 Jun 01 '20 at 15:23
0

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.

treilly94
  • 1
  • 1