i tried to use sonarqube but failed to run it using maven command "mvn sonar:sonar -Dsonar.login=token" - spring-boot

I used sonarqube-spring boot video to learn sonarqube but failed. I had created token from sonarqube and tried "mvn sonar:sonar -Dsonar.login=sqp_e1cf0bc2bf1ea3567f35f4667c2edd2ca37b4c78" from intellij. it shows error Unknown lifecycle phase ".login=". . My Pom file plugins
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.9.1.2184</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

What if you run instead:
mvn -Dsonar.token=your_token -Dsonar.url=sonar_url sonar:sonar
?

Related

Plugin 'maven-clean-plugin:' not found in Intellij IDE

I added the following in my pom.xml.
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>pom-manual-clean</id>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Intellij IDE complains that:
Plugin 'maven-clean-plugin:' not found
Also note that in the auto complete also it does not appear.
What am I doing wrong here?

exec-maven plugin error when executing with mvn clean verify

I get the below error when executing postman tests using exec Maven plugin. What am I doing wrong?
I am fairly new to this, so, any help would be welcomed.
I run it with 'mvn clean verify'
Error:-
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:exec (merge) on project ihtests: Command execution failed.
Plugin:-
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<workingDirectory>.</workingDirectory>
</configuration>
<executions>
<execution>
<id>merge</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>
/node_modules/newman/bin/newman.js
</executable>
<arguments>
npm shipment-tests
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Travis CI - Maven build - Tests are skipped by default

I observed that unit tests are skipped by default during travis-ci builds.
My travis config file
language: java
sudo: false
jdk:
- openjdk11
cache:
directories:
- "$HOME/.m2/repository"
- "$HOME/.sonar/cache"
addons:
sonarcloud:
organization: st-spring-samples
token:
secure: ${SONAR_TOKEN}
script:
- mvn org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar
My travis build output:
Can someone please let me know why travis-ci forces -DskipTests=true option in this case?
Was able to overcome the problem by making use of maven build profiles. Assembly plugin will be invoked only with an explicit build profile. So travis install dependencies phase doesn't kickoff assembly process, hence no assembly error.
<profiles>
<profile>
<id>assemble</id>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.15</version>
<executions>
<execution>
<phase>package</phase>
<inherited>true</inherited>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<finalName>${project.artifactId}-mocks-${project.version}</finalName>
<attach>false</attach>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/wiremock-assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>attach-mock-jar</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>target/${project.artifactId}-mocks-${project.version}.jar</file>
<type>jar</type>
<classifier>mocks</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.15</version>
<executions>
<execution>
<phase>package</phase>
<inherited>true</inherited>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Full pom.xml can be found here
I am still interested to see if there is a better option available. If anyone knows one, please let me know.

Maven Config Plugins running twice

I have the following pom config. I added the cobertura plugin, and now pmd, cpd, findbugs, and test are running twice.
I understand that is because of my "phases" config, but I don't understand how can I achieve the following:
What I want is before I commit to the repo, build my app and check for pmd errors, findbugs errors, check my tests, and check my cobertura.
How can I achieve this? I am used to run "mvn clean package" before commit. It's that ok?
Here's my config:
...
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<configuration>
<linkXref>false</linkXref>
<rulesets>
<!-- Custom Ruleset -->
<ruleset>codequality/pmd.xml</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.4</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<check>
<haltOnFailure>true</haltOnFailure>
<branchRate>70</branchRate>
<lineRate>70</lineRate>
<totalBranchRate>70</totalBranchRate>
<totalLineRate>70</totalLineRate>
<packageLineRate>70</packageLineRate>
<packageBranchRate>70</packageBranchRate>
</check>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any maven plugin has a default execution phase. In this case, the plugins that you apply are executed in the verify phase (pmd-plugin). But you are defining it to run also in the compile phase. Removes the phase tag and lets it run in the verification phase.
<execution>
<!--<phase>compile</phase>-->
<goals>
<goal>...</goal>
...
</goals>
</execution>
Finally, the good practice to validate your project before a commit is to run:
mvn clean verify

Maven and emma plugin

How to configure maven build to fail if some of bundles to instrument are misspelled or no target/coverage/coverage.xml file report is generated?
I did not check, try:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-verifier-plugin</artifactId>
<version>1.0</version>
<configuration>
<verificationFile>target/coverage/coverage.xml</verificationFile>
</configuration>
<executions>
<execution>
<id>main</id>
<phase>package</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Resources