Open dabrowski-adam opened 9 months ago
The task is to update the project's configuration to use Java 17 in response to SonarCloud's deprecation of Java 11.0.14. The solution involves updating various configuration files to ensure that the project is built and analyzed using Java 17. This includes Dockerfiles for containerization, build scripts for Gradle and Maven, CI/CD pipeline configurations for Travis CI and GitLab CI, and a Jenkinsfile for Jenkins pipelines.
The reasoning for the solution is to comply with SonarCloud's requirements and to ensure that the project's build and analysis environments are using a supported version of Java. Updating the Java version in these configuration files will ensure that the project can be built, tested, and analyzed without any issues related to the deprecated Java version.
For the Dockerfile:
# Use a base image that includes Java 17
FROM openjdk:17-slim
# Copy the application's jar file into the image
COPY target/myapp.jar /usr/app/myapp.jar
# Set the working directory
WORKDIR /usr/app
# Expose the port the application runs on
EXPOSE 8080
# Run the application
CMD ["java", "-jar", "myapp.jar"]
For the build.gradle:
plugins {
id 'java'
}
group 'com.yourcompany.yourproject'
version '1.0-SNAPSHOT'
sourceCompatibility = '17'
targetCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
// Your project dependencies
}
For the .travis.yml:
language: java
jdk:
- openjdk17
script:
- ./gradlew build
For the Jenkinsfile:
pipeline {
agent {
docker {
image 'openjdk:17-jdk'
args '-v /home/jenkins/.m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
sh 'java -version'
// Add build steps here
}
}
stage('Test') {
steps {
// Add test steps here
}
}
stage('SonarQube analysis') {
steps {
// Add SonarQube analysis steps here
}
}
}
post {
success {
// Add post-build actions for successful builds
}
failure {
// Add post-build actions for failed builds
}
}
}
For the pom.xml:
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
For the .gitlab-ci.yml:
image: maven:3.8.4-openjdk-17
stages:
- build
- test
- analyze
build_job:
stage: build
script:
- mvn clean install -DskipTests
test_job:
stage: test
script:
- mvn test
sonarcloud_check:
stage: analyze
image: sonarsource/sonar-scanner-cli:latest
script:
- sonar-scanner
only:
- master
- merge_requests
Each of these snippets should be placed in their respective files, replacing or adding to the existing content as necessary. It's important to test these changes to ensure that the build and analysis processes work correctly with Java 17.
Click here to create a Pull Request with the proposed solution
Files used for this task:
The version of Java (11.0.14) you have used to run this analysis is deprecated and we will stop accepting it soon. @autopilot, please update to at least Java 17. Read more here