Build fails with "invalid target release: 11" message.
After a commit to bitbucket, a pipeline job starts automaticly but fails with
Full Error Message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project sms-commons: Fatal error compiling: invalid target release: 11 ->
How to enable java 11 support?
image: maven:3.3.9
pipelines:
default:
- step:
caches:
- maven
script: # Modify the commands below to build your repository.
- mvn -B verify # -B batch mode makes Maven less verbose
- mvn clean install
I expect a successfull build, but as I wrote the build job fails.
You need to use a newer version of the maven Compiler Plugin
org.apache.maven.plugins
maven-compiler-plugin
3.8.0
And you need a maven Docker image that is providing java 11 for example maven:3-jdk-11
I use: ehsaniara/bitbucket-util as Docker Image.
example:
options:
docker: true
pipelines:
branches:
master:
- step:
name: Production Build on Master
image: ehsaniara/bitbucket-util:latest
trigger: automatic
script:
- mvn clean install
You need maven image which supports jdk 11, so update your "image" value like below:
image: maven:3.8.3-jdk-11
pipelines:
default:
- step:
caches:
- maven
script: # Modify the commands below to build your repository.
- mvn -B verify # -B batch mode makes Maven less verbose
- mvn clean install
Related
I'm building a pipeline in GitLab CI/CD with the .gitlab-ci.yml file. It's a Java application, gradle is the build too and I have to push this artifact to GCP AR.
So I'm using a gradle image and I don't know where after the build my artifact is located and the syntax I'll use to push that artifact to Google Artifact.
Below is my progress:
image: gradle:alpine
stages:
- build
- test
Build_Stage:
stage: build
script:
- gradle build
cache:
paths:
- build
- .gradle
Test_Job:
stage: test
script:
- gradle check
cache:
paths:
- build
- .gradle
after_script:
- echo "End of CI"
console output on GitLab I don't even know if it actually build a .jar and where the .jar package is at
.gitlab.yml has following
stages:
- test
- publish
- deploy
- manual
# Test all commits regardless of branch in a WildFly 10 instance
test:wf10:
stage: test
script:
- mvn clean test -U -Dprofile.wildfly10 -Dwildfly10.servergroup=masterdata-web
tags:
- test
# Publish tagged release to Artifactory (WildFly 10)
publish-release:wf10:
stage: publish
only:
- /^v-.*$/
script:
- mvn clean deploy -B -U -P wildfly10 -Dmaven.test.skip=true
tags:
- test
# Manually deploy any build to WildFly 10 servergroup Masterdata-web
deploy-test:wf10:
stage: manual
environment:
name: test
script:
- mvn clean package wildfly:undeploy wildfly:deploy -B -U -P wildfly10 -Dmaven.test.skip=true -Dwildfly10.servergroup=masterdata-web
tags:
- test
when: manual
# Manually deploy tagged release to WildFly 10 servergroup Masterdata-web
deploy-qa:wf10:
stage: manual
environment:
name: qa
script:
- mvn clean package wildfly:undeploy wildfly:deploy -B -U -P wildfly10 -Dmaven.test.skip=true -Dwildfly10.servergroup=masterdata-web
tags:
- qa
when: manual
# Automatically deploy build staged for release to WildFly 10 servergroup Masterdata-web
deploy-release-qa:wf10:
stage: deploy
environment:
name: qa
only:
- master
except:
- /^v-.*$/
script:
- mvn clean package wildfly:undeploy wildfly:deploy -B -U -P wildfly10 -Dmaven.test.skip=true -Dwildfly10.servergroup=masterdata-web
tags:
- qa
when: manual
# Automaticaly deploy tagged release to WildFly 10 servergroup Masterdata-web
deploy-release-prod:wf10:
stage: deploy
environment:
name: prod
only:
- /^v-.*$/
script:
- mvn clean package wildfly:undeploy wildfly:deploy -B -U -P wildfly10 -Dmaven.test.skip=true -Dwildfly10.servergroup=terp
tags:
- prod
# Manually generate project report for WildFly 10, report is stored for 2 weeks
generate-report:wf10:
stage: manual
script:
- mvn clean test site:site -B -U -P wildfly10
- mv target/site ./
artifacts:
name: report-wf10
expire_in: 2 weeks
paths:
- site
tags:
- test
when: manual
# Manual deploy tagged release to WildFly 10 servergroup servicedesk in PROD
deploy-prod:wf10:
stage: deploy
environment:
name: prod
#only:
# - /^v-.*$/
script:
- mvn clean package -B -U wildfly:undeploy wildfly:deploy -Dprofile.wildfly10 -Dmaven.test.skip=true -Dwildfly10.servergroup=terp
tags:
- prod
when: manual
For release every time, I need to run following commands by check out branch:
mvn release:prepare -Darguments=-Dprofile.wildfly10 -DignoreSnapshots=true
mvn release:clean
git push --follow-tags
Then it relaeases without SNAPSHOT
If i create manual branch it always append SNAPSHOT.
Can you suggest how to create manual pipeline which deploys without SNapshot and from Gitlab only?
Maven is doing exactly what you have ordered it to do. The command like:
mvn clean deploy -B -U -P wildfly10 -Dmaven.test.skip=true
orders maven to compile, package and deploy artifacts to remote repository, and when doing that maven picks up target version from pom.xml, thus to build and deploy artifacts with specific version you need to tell maven what version to use explicitly or implicitly, for example, when you are doing:
mvn release:prepare -Darguments=-Dprofile.wildfly10 -DignoreSnapshots=true
git push --follow-tags
maven-release-plugin creates two commits in SCM: the first one with "release" version in pom.xml (accompanied by tag/branch), the second one with "snapshot" version, and the first commit triggers your publish job. That explains why creating branch manually does not makes sense.
There are a couple of options to implement release management in maven project using GitLab:
create pipeline forms in GitLab to request information about releaseVersion and developmentVersion, in that case maven release command would be something like mvn --batch-mode -Prelease release:clean release:prepare -DreleaseVersion=${releaseVersion} DdevelopmentVersion=${developmentVersion} (most likely extra setup will required to allow maven to push changes)
let maven to choose versions automatically (or implement version policies), alternatively you make take advantage of using my extension: version-policy-extension
use Maven CI Friendly Versions - in that case you will need to pass ${revision} from GitLab
implement external tools (scripts, docker images) to automate that
I configurd the .gitlab-ci.yml, it is a java project and needs to maven repository, my local repository is nexus, I downloading the dependency from nexux successfully , but For each build it still downloads all the dependencies every time from nexus and it don't caching.
.gitlab-ci.yml configuration is :
image: nexus.local.ir:8095/maven:3.6.3-jdk-8
######## run image #########
stages:
- build
cache:
key: maven-cache
paths:
- .m2/repository
######### cache ############
build:
stage: build
script:
- mvn package -s config/settings.xml -Dmaven.test.skip=true
I will try to keep the description brief. We have a couple of projects. Some of them are full blown Spring Boot apps, some of them are Maven Dependency projects (used in those Spring Boot apps).
I have set up a Jenkins server for automating pipelines. Jenkins calls Google Cloud Build to build projects/docker images and cache dependencies. It also calls SonarQube in a step. This all works fine for the Spring Boot apps, but the SonarQube step fails for the dependency projects. The error is Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project projectname: Not inside a Git work tree: / -> [Help 1].
The Dockerfile for the project:
FROM maven:3.5-jdk-8-alpine
# Copy local code to the container image.
COPY pom.xml settings.xml ./
RUN mvn -s settings.xml dependency:go-offline
COPY src ./src
# Build a release artifact.
RUN mvn verify -DskipTests -s settings.xml
The cloudbuild.yaml:
substitutions:
_IMAGE_NAME: "projectname"
steps:
- name: "docker"
entrypoint: "sh"
args:
- "-c"
- |-
docker pull gcr.io/gcp-project/${_IMAGE_NAME}:$_TAG
docker pull gcr.io/gcp-project/${_IMAGE_NAME}:latest || true
- name: "docker"
args:
- "build"
- "-t"
- "gcr.io/gcp-project/${_IMAGE_NAME}"
- "-t"
- "gcr.io/gcp-project/${_IMAGE_NAME}:$_TAG"
- "--cache-from"
- "gcr.io/gcp-project/${_IMAGE_NAME}:latest"
- "--cache-from"
- "gcr.io/gcp-project/${_IMAGE_NAME}:$_TAG"
- "."
- name: "gcr.io/gcp-project/${_IMAGE_NAME}"
entrypoint: "bash"
args:
- "-ce"
- |-
mvn -f /pom.xml -s ./settings.xml sonar:sonar -Dsonar.host.url=https://sonar.server.com -Dsonar.login=${_SONAR_KEY}
- name: "gcr.io/gcp-project/${_IMAGE_NAME}"
args:
- "mvn"
- "deploy"
- "-s"
- "/settings.xml"
images: ["gcr.io/gcp-project/${_IMAGE_NAME}"]
There are two very confusing things. If i run the maven command locally, the analysis completes successfully. Also, if i run the local Google Cloud Build tool (cloud-build-local) it also passes.
I have verified that the .git folder is not uploaded. It is neither with the Spring Boot apps.
I copied the settings.xml from the Jenkins server locally and used that one. Neither the Spring Boot apps or the dependencies define a sonar-project.properties.
Is there anyone who can shed some light on this?
Thanks in advance!
EDIT
I created 2 repositories that are able to replicate this problem:
Non-working: https://github.com/claystation/mvnsonarapp
Working: https://github.com/claystation/mvnsonarappworking
I think the main difference is the dependency project not having #SpringBootApplication?
Ok, so i finally figured it out how to solve this, by doing the MCVE.. Unfortunately not WHY the problem exists.
The main difference between the projects was the #SpringBootApplication annotation. I thought this might have something to do with having the spring-boot-starter-parent parent defined.
I removed the parent part and now my project is passing in Sonar. If there is ever someone who can explain WHY Sonar gives this error with the parent defined but no #SpringBootApplication annotation, that would be very helpful.
Thanks!
I am using Github actions to set up a continuous integration workflow for a Maven app. The Maven app depends on some external dependencies as well as a couple other repositories that we built. In my Github action's .yaml file, I've included the line "mvn install". When I make a commit, the action begins to run the .yaml file as expected. The build mostly works, and can find external maven dependencies from maven central. However, the build cannot find the two other private repositories. These repositories are saved on the same github account as the repo. for this app.
Downloading from central: https://repo.maven.apache.org/maven2/com/<repo>/1.3/<repoName>-1.3.pom
[WARNING] The POM for com.<repo>/<reponame>.core:jar:1.3 is missing, no dependency information available
Here is my github/workflow action's yaml file...
name: Build1
on:
push:
branches:
- '*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Run a one-line script
run: echo Hello, world!
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
- name: Build
run: mvn install