Issue
I'm cloning the project from git and doing the mvn clean test package sonar:sonar and deploy but the project doesn't run , I tried the free-style job too but it's the same it's spring boot JAR application
pipeline {
agent any
stages{
stage('Git') {
steps {
echo "Cloning"
git branch: '*****', url: 'https://github.com/****.git'
}
}
stage('clean') {
steps{
echo "Cleaning the project"
bat 'mvn clean'
}
}
stage('Test') {
steps {
echo "Doing the tests"
bat 'mvn test'
}
}
stage('SONAR') {
steps{
echo "Cleaning Code";
bat 'mvn sonar:sonar';
}
}
stage('MVN PACKAGE') {
steps{
echo "packing the project";
bat 'mvn package';
}
post{
success {
archiveArtifacts 'target/*.jar';
}
}
}
stage('NEXUS') {
steps{
echo "Deploying the project";
bat 'mvn deploy:deploy-file -DgroupId=**** -DartifactId=**** -Dversion=1.0 -DgeneratePom=true -Dpackaging=jar -DrepositoryId=deploymentRepo -Durl=http://localhost:8081/repository/maven-releases/ -Dfile=target/****-1.0.jar ';
}
}
} ...}}
as the Tomcat does no start running , my Tests aren't running , it's supposed to do 6 tests
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 46.816 s
[INFO] Finished at: 2020-11-05T02:52:20+01:00
[INFO] ------------------------------------------------------------------------
even sonar isn't showing the unit tests in the project, Can you please help me?
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>tn.esprit.spring</groupId>
<artifactId>timesheet</artifactId>
<version>1.0</version>
<name>timesheet</name>
<description>timesheet</description>
<properties>
<java.version>1.8</java.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
mvn compile
D:\2-SPRING\jenkins\jenkins\workspace\pipeline timesheet project>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< tn.esprit.spring:timesheet >---------------------
[INFO] Building timesheet 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ timesheet ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ timesheet ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 35 source files to D:\2-SPRING\jenkins\jenkins\workspace\pipeline timesheet project\src\main\webapp\WEB-INF\classes
[INFO] /D:/2-SPRING/jenkins/jenkins/workspace/pipeline timesheet project/src/main/java/tn/esprit/spring/TimesheetApplication.java: D:\2-SPRING\jenkins\jenkins\workspace\pipeline timesheet project\src\main\java\tn\esprit\spring\TimesheetApplication.java uses unchecked or unsafe operations.
[INFO] /D:/2-SPRING/jenkins/jenkins/workspace/pipeline timesheet project/src/main/java/tn/esprit/spring/TimesheetApplication.java: Recompile with -Xlint:unchecked for details.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 39.156 s
[INFO] Finished at: 2020-11-05T04:07:57+01:00
[INFO] ------------------------------------------------------------------------
mvn sonar:sonar
D:\2-SPRING\jenkins\jenkins\workspace\pipeline timesheet project>mvn sonar:sonar
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< tn.esprit.spring:timesheet >---------------------
[INFO] Building timesheet 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- sonar-maven-plugin:3.7.0.1746:sonar (default-cli) @ timesheet ---
[INFO] User cache: C:\windows\system32\config\systemprofile\.sonar\cache
[INFO] SonarQube version: 6.7.7
[INFO] Default locale: "fr_FR", source code encoding: "UTF-8"
[INFO] Publish mode
[INFO] Load global settings
[INFO] Load global settings (done) | time=1186ms
[INFO] Server id: BF41A1F2-AXWFQCU12uRh5xSTg2DK
[INFO] User cache: C:\windows\system32\config\systemprofile\.sonar\cache
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=230ms
[INFO] Process project properties
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=2067ms
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=1483ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=3900ms
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=380ms
[INFO] Project key: tn.esprit.spring:timesheet
[INFO] ------------- Scan timesheet
[INFO] Load server rules
[INFO] Load server rules (done) | time=160ms
[INFO] Base dir: D:\2-SPRING\jenkins\jenkins\workspace\pipeline timesheet project
[INFO] Working dir: D:\2-SPRING\jenkins\jenkins\workspace\pipeline timesheet project\target\sonar
[INFO] Source paths: pom.xml, src/main/java
[INFO] Test paths: src/test/java
[INFO] Source encoding: UTF-8, default locale: fr_FR
[INFO] Index files
[INFO] 39 files indexed
[INFO] Quality profile for java: Sonar way
[INFO] Quality profile for xml: Sonar way
[INFO] Sensor JavaSquidSensor [java]
[INFO] Configured Java source version (sonar.java.source): 8
[INFO] JavaClasspath initialization
[INFO] JavaClasspath initialization (done) | time=80ms
[INFO] JavaTestClasspath initialization
[INFO] JavaTestClasspath initialization (done) | time=10ms
[INFO] Java Main Files AST scan
[INFO] 35 source files to be analyzed
[INFO] 35/35 source files have been analyzed
[WARNING] Classes not found during the analysis : [javax.annotation.meta.When]
[INFO] Java Main Files AST scan (done) | time=4596ms
[INFO] Java Test Files AST scan
[INFO] 3 source files to be analyzed
[INFO] 3/3 source files have been analyzed
[INFO] Java Test Files AST scan (done) | time=90ms
[INFO] Sensor JavaSquidSensor [java] (done) | time=6680ms
[INFO] Sensor SurefireSensor [java]
[INFO] parsing [D:\2-SPRING\jenkins\jenkins\workspace\pipeline timesheet project\target\surefire-reports]
[INFO] Sensor SurefireSensor [java] (done) | time=0ms
[INFO] Sensor JaCoCoSensor [java]
[INFO] Sensor JaCoCoSensor [java] (done) | time=0ms
[INFO] Sensor SonarJavaXmlFileSensor [java]
[INFO] 1 source files to be analyzed
[INFO] Sensor SonarJavaXmlFileSensor [java] (done) | time=3850ms
[INFO] 1/1 source files have been analyzed
[INFO] Sensor XML Sensor [xml]
[INFO] Sensor XML Sensor [xml] (done) | time=510ms
[INFO] Sensor Analyzer for "php.ini" files [php]
[INFO] Sensor Analyzer for "php.ini" files [php] (done) | time=30ms
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=170ms
[INFO] Sensor CPD Block Indexer
[INFO] Sensor CPD Block Indexer (done) | time=130ms
[INFO] 11 files had no CPD blocks
[INFO] Calculating CPD for 24 files
[INFO] CPD calculation finished
[INFO] Analysis report generated in 679ms, dir size=187 KB
[INFO] Analysis reports compressed in 160ms, zip size=107 KB
[INFO] Analysis report uploaded in 90ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/tn.esprit.spring:timesheet
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at http://localhost:9000/api/ce/task?id=AXWWYaz_JnFpsXr-KFku
[INFO] Task total time: 57.427 s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:22 min
[INFO] Finished at: 2020-11-05T04:09:45+01:00
[INFO] ------------------------------------------------------------------------
deploy
D:\2-SPRING\jenkins\jenkins\workspace\pipeline timesheet project>mvn deploy:deploy-file -DgroupId=tn.esprit -DartifactId=timesheet -Dversion=1.0 -DgeneratePom=true -Dpackaging=jar -DrepositoryId=deploymentRepo -Durl=http://localhost:8081/repository/maven-releases/ -Dfile=target/timesheet-1.0.jar
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< tn.esprit.spring:timesheet>---------------------
[INFO] Building timesheet 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy-file (default-cli) @ timesheet ---
Uploading to deploymentRepo: http://localhost:8081/repository/maven-releases/tn/esprit/timesheet/1.0/timesheet-1.0.jar
Uploaded to deploymentRepo: http://localhost:8081/repository/maven-releases/tn/esprit/timesheet/1.0/timesheet-1.0.jar (54 MB at 6.5 MB/s)
Uploading to deploymentRepo: http://localhost:8081/repository/maven-releases/tn/esprit/timesheet/1.0/timesheet-1.0.pom
Progress (1): 390 B
Uploaded to deploymentRepo: http://localhost:8081/repository/maven-releases/tn/esprit/timesheet/1.0/timesheet-1.0.pom (390 B at 82 B/s)
Downloading from deploymentRepo: http://localhost:8081/repository/maven-releases/tn/esprit/timesheet/maven-metadata.xml
Uploading to deploymentRepo: http://localhost:8081/repository/maven-releases/tn/esprit/timesheet/maven-metadata.xml
Progress (1): 294 B
Uploaded to deploymentRepo: http://localhost:8081/repository/maven-releases/tn/esprit/timesheet/maven-metadata.xml (294 B at 104 B/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.030 s
[INFO] Finished at: 2020-11-05T04:10:36+01:00
[INFO] ------------------------------------------------------------------------
[Pipeline] }
Solution
I fixed the problem , I added maven-surefire plugin , took off the junit dependency ( I put it bcz I faced error while deploying to nexus and after changing it the deploying worked) , and to fix the 401 unauthorized error in mvn deploy:deploy , I just changed mvn version from 3.5. to 3.6.3
Answered By - R_pri
Answer Checked By - Timothy Miller (JavaFixing Admin)