mvn sonar:sonar do not use <libraries> in pom.xml - maven

i've got a problem with an sonar analysis trought maven.
in my pom.xml i define a tag under
my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
<modelVersion 4.0.0</modelVersion>
<groupId>com.myorg</groupId>
<artifactId>android-project</artifactId>
<name>android project</name>
<version>2.3.${HUDSON_SVN_REVISION}</version>
<build>
<sourceDirectory>src</sourceDirectory>
<outputDirectory>bin</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
<libraries>libs/android.jar</libraries>
</properties>
</project>
I run maven in hudson with sonar plugin, the build is succesfull but i have some warning in the output log of hudson:
[INFO] Findbugs output report: C:\hudson\jobs\test_sonar_pdf\workspace\target\sonar\findbugs-result.xml
The following classes needed for analysis were missing:
android.appwidget.AppWidgetProvider
android.os.AsyncTask
android.app.Activity
...
But i'm sure that the android.jar is under libs folder.
Perhaps there is a syntax problem?
thanks for your help.

The tag is only used for the Ant task or the Simple Java Runner.
With Maven, you have to define your dependencies using the standard Maven section of the POM (see http://maven.apache.org/pom.html#Dependencies).

thanks to you Fabrice, ly pom.xml file. I hope could help someone else
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myorg</groupId>
<artifactId>android-project</artifactId>
<name>android project</name>
<!-- Dans hudson, dans action a la suite du build, dans la partie sonar, dans propriete additionelles, ajouter
-DHUDSON_SVN_REVISION=${SVN_REVISION} -->
<version>2.3.${HUDSON_SVN_REVISION}</version>
<dependencies>
<dependency>
<groupId>deps</groupId>
<artifactId>dep1</artifactId>
<version>0.1</version>
<scope>system</scope>
<systemPath>${basedir}/libs/edtftpj.jar</systemPath>
</dependency>
</dependencies>
<dependency>
<groupId>deps</groupId>
<artifactId>dep2</artifactId>
<version>0.2</version>
<scope>system</scope>
<systemPath>C:\android\android-sdk-windows\platforms\android-7\android.jar</systemPath>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<outputDirectory>bin</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
</properties>
</project>

Related

Why the maven don't run the test file?

This is my file directory。
And my pom.xml is that
'''
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="https://maven.apache.org/POM/4.0.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- <properties> -->
<!-- <maven.compiler.source>1.8</maven.compiler.source> -->
<!-- <maven.compiler.target>1.8</maven.compiler.target> -->
<!-- <argLine>-Dfile.encoding=UTF-8</argLine> -->
<!-- </properties> -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<groupId>org.example</groupId>
<artifactId>SE-Mapping</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<skipTests>false</skipTests>
<includes>
<!--<include>*\*\*\*Test.java</include>-->
<include>**/**/*Test.java</include>
<include>**/*Test.java</include>
<include>*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.16.0</version>
</dependency>
</dependencies>
</project>
'''
but when I run the "mvn test",it tell me that
It doesn't seem to run the test file I provided.And it donesn't generate the report.
How can I run the test file I provided ?
thanks.
see answer Maven does not find JUnit tests to run

Spring boot maven plugin not packaging java classes in Openshift environment

I have a multi-module maven project whose one of these modules uses Spring Boot.
When I package my jar in my PC it works fine and all java classes are included in the jar, but when I do this in an Openshift environment, only the web resources are included, not the java classes.
I have an Openshift DIY cartridge in which, using action hooks I setup the environment, package my jar and run it.
This procedure worked fine until I made some recent changes, which were to divide my maven project into modules.
parent pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>XXXX</groupId>
<artifactId>XXXX</artifactId>
<version>XXXX</version>
<packaging>pom</packaging>
<modules>
<module>data</module>
<module>web</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.compiler.plugin.version>3.5</maven.compiler.plugin.version>
<maven.jar.plugin.version>3.0.2</maven.jar.plugin.version>
<maven.clean.plugin.version>2.5</maven.clean.plugin.version>
<maven.spring-boot-maven-plugin.version>1.3.3.RELEASE</maven.spring-boot-maven-plugin.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven.clean.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${maven.spring-boot-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
...
</dependencies>
</dependencyManagement>
<dependencies>
....
</dependencies>
web module pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>XXXX</groupId>
<artifactId>XXXX</artifactId>
<version>1.2.3</version>
</parent>
<artifactId>XXXX</artifactId>
<packaging>jar</packaging>
<properties>
...
</properties>
<build>
<finalName>${project.name}-${project.version}</finalName>
<resources>
<resource>
<directory>${project.resources.path}</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>deployments</directory>
<includes>
<include>*.jar</include>
<followSymlinks>false</followSymlinks>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>XXXX</mainClass>
<finalName>XXXX</finalName>
<outputDirectory>../deployments</outputDirectory>
<excludeGroupIds>org.seleniumhq.selenium,org.projectlombok</excludeGroupIds>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
....
</dependencies>
data module pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>XXXX</groupId>
<artifactId>XXXX</artifactId>
<version>1.2.3</version>
</parent>
<artifactId>XXXX</artifactId>
<packaging>jar</packaging>
<properties>
....
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
....
</dependencies>
Maven command I use to package the jar (executed in Openshift cartridge)
${OPENSHIFT_DATA_DIR}${MVN_LINK}/bin/mvn clean install -s
.openshift/action_hooks/settings.xml -DskipTests=true -P prod
mvn -v command in my Openshift box
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11- 10T11:41:47-05:00)
Maven home: /var/lib/openshift/5713d8630c1e66bfc5000085/app- root/data/maven
Java version: 1.8.0_101, vendor: Oracle Corporation
Java home: /var/lib/openshift/5713d8630c1e66bfc5000085/app- root/data/jdk1.8.0_101/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-573.26.1.el6.x86_64", arch: "i386", family: "unix"
The resulting jar contains all the libs, .properties files, web resources etc. but no sign of the java classes...
What am I missing? why are not the java classes being packaged too?
Many thanks
CASE CLOSED
I found the issue. I gitignored the src folder of the web module by mistake, therefore nothing was being committed to the git repository of the Openshift cartridge, hence it wasn't packaging any java files in the jar, because there were none! Shame on me! ;-)

How to use maven-install-plugin to install-file for module

With this projects structure I cannot install the sqljdbc4.jar to my local maven repository.
This is LiferayBuild/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>...</groupId>
<artifactId>LiferayBuild</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>LiferayBuild</name>
<description>Liferay Aggregator Project (build modules)</description>
<properties>
...
</properties>
<modules>
...
<module>../Liferay</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<file>${basedir}/lib/sqljdbc4-4.0.jar</file>
<packaging>jar</packaging>
<generatePom>false</generatePom>
<pomFile>../Liferay/pom.xml</pomFile>
</configuration>
<executions>
<execution>
<id>inst_sql</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
And this is Liferay/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>...</groupId>
<artifactId>Liferay</artifactId>
<version>1.2.1</version>
<name>Liferay</name>
<description>Liferay Connector</description>
<properties>
...
</properties>
<dependencies>
...
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
...
</dependencies>
<!-- Build Settings -->
<build>
<resources>
...
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
...
</plugins>
</build>
<pluginRepositories>
...
</pluginRepositories>
<profiles>
<profile>
...
</profile>
</profiles>
When I Run as... Maven install, I get a BUILD FAILURE
[ERROR] Failed to execute goal on project Liferay: Could not resolve dependencies for project com.realsoft:Liferay:jar:1.2.1: Failure to find com.microsoft.sqlserver:sqljdbc4:jar:4.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
What can I do to get the jar installed to my local repository? I have already tried the suggestions from http://blog.valdaris.com/post/custom-jar/ but with no outcome. Please help!
Thanks, I have used
<phase>clean</phase>
and moved the lib folder to my basedir of my multi-module project.

Jenkins package project out of his workspace

I tried to build maven war projects with Jenkins.
Jenkins pulls the code and builds the project. However, the build is not in the workspace, but rather in a folder with the project source. I think Jenkins takes the target folder from maven pom file and builds it.
How can I tune Jenkins to make a build and deploy pipeline?
In the deploy phase Jenkins cannot find war file.
OS is windows, IDE - eclipse.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.test.webapp</groupId>
<artifactId>webApp</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>webApp</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>8.0.5</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<directory>${basedir}\target</directory> <!-- tried with this line and without -->
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
The way I coped with a problem:
In pom.xml:
<properties>
<baseFolder>${basedir}</baseFolder>
</properties>
<build>
<directory>${baseFolder}/target</directory>
</directory>
In Jenkins run build maven build with properties
baseFolder=$WORKSPACE

maven-surefire-report-plugin not generating surefire-report.html

I'm unable to get the maven-surefire-report-plugin to generate the surefire-report.html when I run:
mvn clean deploy site
mvn clean site
mvn site
mvn clean install site
The only time I've been able to get the report generated is when I run:
mvn surefire-report:report
Here is a look at my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>blah.blah</groupId>
<artifactId>build</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>build</name>
<description>build</description>
<properties>
...
</properties>
<modules>
<module>../report</module>
</modules>
<dependencyManagement>
<dependencies>
...
<!-- Custom local repository dependencies -->
<dependency>
<groupId>asm</groupId>
<artifactId>asm-commons</artifactId>
<version>3.1</version>
</dependency>
...
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx1024m -XX:MaxPermSize=256m -XX:-UseGCOverheadLimit -Dsun.lang.ClassLoader.allowArraySyntax=true</argLine>
<includes>
<include>**/*Test.java</include>
<include>**/*_UT.java</include>
</includes>
<excludes>
<exclude>**/*_IT.java</exclude>
<exclude>**/*_DIT.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.7.2</version>
</plugin>
</plugins>
</reporting>
</project>
There are 2 tests in my project and TEST-*.xml files are generated in surefire-reports
Also, the site folder is generated with a css and images folder and contents, but no report.
There is a similar issues reported in JIRA, the solution is to use later version of maven-site-plugin 3.0-x in your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
...
</plugins>
</build>
After testcases running finished, you can CMD mvn surefire-report:report-only to generate test report

Resources