I have a problem setting up sonarcloud on my microservices.
Which service should i include the below as instructed, considering the structure of my project
Would you consider this a monorepo? If so – you would probably want to consider configuring a monorepo which would mean setting up analysis for each project in the repo.
I have read the resource and it’s quite helpful in understanding the setup the more… but my question was not answered there. As regard the pom.xml, where should i place the properties ? on each of the projects or what?
The workflow is not valid. .github/workflows/build.yml (Line: 40, Col: 9): Unexpected value 'run' .github/workflows/build.yml (Line: 34, Col: 9): Required property is missing: uses
The line 40 it is complaining of is the run: ... above
Since you aren’t using the official GitHub action, you can’t use with: projectBaseDir .... and need to pass sonar.projectBaseDir to your mvn command.
Confirm the below configuration is fine. I need to get this sorted today and see how it works before introducing our private project.
Current error
Error: The goal you specified requires a project to execute but there is no POM in this directory (/home/runner/work/Blinx-Microservice/Blinx-Microservice). Please verify you invoked Maven from the correct directory.
Below is my implementation.
name: My Test Monorepo Project
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
cloudGatwayService:
name: CloudGatwayService
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=BlinxCode_Blinx-Microservice
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
serviceRegistry:
name: ServiceRegistry
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=BlinxCode_Blinx-Microservice
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
userIdentityService:
name: UserIdentityService
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=BlinxCode_Blinx-Microservice
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Error: The goal you specified requires a project to execute but there is no POM in this directory (/home/runner/work/Blinx-Microservice/Blinx-Microservice). Please verify you invoked Maven from the correct directory. -> [Help 1]
org.apache.maven.lifecycle.MissingProjectException: The goal you specified requires a project to execute but there is no POM in this directory (/home/runner/work/Blinx-Microservice/Blinx-Microservice). Please verify you invoked Maven from the correct directory.
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:85)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
@Colin Please and Please i need to get over this to show our IT department how Sonarcloud can help us before going for the Enterprise. The last question is pretty straight forward, If possible, the product is public, you can check it out.
Looking at your project and the error message from your latest GitHub Actions run, it seems that you need to remove Blinx-Microservice from the projectBaseDir configuration:
Let me know if that works. Also, if you are going with the monorepo setup, you will need three different project keys in your configuration. If you have imported your repository as a monorepo on SonarCloud (docs) then you will be able to add multiple projects within that repository.
The mvn command seems to be run in the root folder, where there is no pom.xml in your case. You could try changing the working directory for the various GitHub Actions jobs to the relevant subfolders as described here.
I’ve forked your repo and created a sample configuration here that works (I’ve had to skip tests for some of the projects). Feel free to check it out and let me know if you have any questions.