Analyze multiple Java projects and one Angular project from a bitbucket pipeline

We have Spring Boot application with multiple modules and one Angular project in the same repository.
Project structure is like this:
app-1
app-1-dto
app-2
app-2-dto
app-2-feign
app-2-stream
app-web
app-web-angular

Each project has pom.xml and capable of producing artifacts, root pom.xml handles build process for the whole repository and in the bitbucket pipeline for the backend is configured like this:

   - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - maven
          - sonar
        script:
          - mvn -B org.jacoco:jacoco-maven-plugin:prepare-agent verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -pl !app-web-angular -Dbitbucket=true
        artifacts:
          - target/**

So this works for java side of the code. I tried to configure another step for Typescript (Angular) like this:

   - step: &build-test-front-end
            name: npm app-web-angular
            image: feeni/node-chrome:latest
            caches:
              - node
              - sonar
            script:
              - cd app-web-angular
              - npm install --quiet
              - npm update caniuse-lite browserslist
              - npm run test -- --code-coverage --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox
              - pipe: sonarsource/sonarcloud-scan:0.1.5
                variables:
                  SONAR_TOKEN: ${SONAR_TOKEN}
                  EXTRA_ARGS: '-Dsonar.projectBaseDir=../ -Dsonar.sources=app-web-angular/src -Dsonar.tests=app-web-angular/src -Dsonar.exclusions=**/node_modules/**,**/*.spec.ts,**/e2e/**,**/coverage/** -Dsonar.test.inclusions="**/testing/**,**/*.spec.ts" -Dsonar.typescript.tsconfigPath=app-web-angular/tslint.json -Dsonar.typescript.lcov.reportPaths=app-web-angular/coverage/lcov.info'

So step is successful too when running individually but it doesn’t produce any activity in the sonarcloud for the branch.

INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=28ms
INFO: 181 files had no CPD blocks
INFO: Calculating CPD for 825 files
INFO: CPD calculation finished
INFO: SCM writing changed lines
INFO: SCM writing changed lines (done) | time=5ms
INFO: Analysis report generated in 160ms, dir size=1 MB
INFO: Analysis report compressed in 1223ms, zip size=1 MB
INFO: Analysis report uploaded in 680ms
INFO: ANALYSIS SUCCESSFUL, you can browse https://sonarcloud.io/dashboard?id=XXXXXXXXXXXXX&branch=feature%2Fsonarcloud-for-front-end-support&resolved=false
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 https://sonarcloud.io/api/ce/task?id=XXXXXXXX
INFO: Analysis total time: 50.367 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:12.965s
INFO: Final Memory: 29M/114M
INFO: ------------------------------------------------------------------------
✔ SonarCloud analysis was successful.

What am I missing?

Thank you,
Sergey

Hi Sergey,

Welcome to our forum ! :slight_smile:

Here is what we would suggest to do :

  • Create only one step to analyse your entire project
  • In the scripts of the step:
    • Start by generating the coverage and test report files for your angular project
    • Then launch the mvn command on the whole project to generate the report. You will have to put the EXTRA_ARGS (of your current 2nd step) in the pom.xml of your angular module so that the analyzer find the coverage and test report files.

We are aware that analysing project with multiple modules and languages is not optimal and we’d like to see how we can improve that. We would be very glad if you could share the link to your repos if it’s public, so we would be able to perform some tests to improve the overall experience.

Thanks,

Hi,

Thank you so much for sharing this idea. I will definitely try it. Unfortunately this is not a public project, but I can probably create a test one similar in structure and share it with you.

In the mean time I have another question. We were running only mvn step before, starting with master branch and against other feature branches and/or PRs. Now with the branch I work with I disabled mvn step and only have angular (npm) step running. This step performs fine, but I don’t see and source code or any other activity on that branch in sonarcloud project. Is this expected? Do I need to change anything in the configuration of the project? Please see the attachments.

Hi Sergey,

Can you share your definition of pipelines of your bitbucket-pipelines.yml?

Are the logs that you shared related to a branch or PR analysis from bitbucket pipelines?

Have you seen our example projects here maybe that could help you.

Hope it helps!
Cheers

I’m trying to do something similar, did you ever get this configured and working?

Trying to get results of angular project published via maven in sonarcloud.

Hi @TonyBrasunas, and welcome to the community!

I suggest to start a new thread for your scenario. Extra tips for when you do that:

  • The new post offers a template with many questions. Please answer in details, so we get a good understanding of your scenario.
  • If you are using bitbucket pipelines, then please share its definition, if possible.
  • As mentioned in this thread, make sure to use a single step for the analysis.

(update) … and now I see you actually did post, before I noticed. Ok then!

1 Like

@TonyBrasunas and everyone else with this problem:

I got it working for me in a gradle project, but it should also work for maven. In the parent build.gradle (or pom) I added the following properties: (this is gradle dialect, you’d have to translate it into maven dialect)

property "sonar.sources", "src/main/java, angular-app/src"
property "sonar.tests", "src/test/java"

In my angular project I added a build.gradle (pom in your case) with this content:

plugins {
  id 'java'
  id("com.github.node-gradle.node") version "2.2.0"
}

node {
  version = '12.13.1'
  npmVersion = '6.12.1'
  download = true
}

jar.dependsOn 'npm_run_build'

All my Java and Angular projects are submoduls to my gradle root project. In my build script I call gradle sonar:sonar which executes sonar analysis for all gradle moduls and submoduls.

2 Likes