I'm using IntelliJ with Maven for my project and i have to analyze it with SonarQube, but when I scan my project with the command provided by the webApp it only analyzes the pom.xml file ignoring the rest of the project.
Analysis results
clean install sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login="the corresponding key here"
My pom.xml (what is inside the project tag):
<groupId>cl.itau.simulacionCredito</groupId>
<artifactId>SimulacionCreditoIntelliJ</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.beust/jcommander -->
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.72</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<excludes>
<exclude>**/HomeTest.java</exclude>
<exclude>**/PropuestaTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.5.0.1254</version>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>SimulacionCredito</id>
<name>SimulacionCredito</name>
<url>file:C:\Users\Pc\IdeaProjects</url>
</repository>
</distributionManagement>
I also tried to use this inside the configuration tag:
<sonar.sources>src/main/java</sonar.sources>
And this happened:
Second analysis
My settings.xml in Maven's conf:
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<proxies>
</proxies>
<servers>
</servers>
<mirrors>
</mirrors>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>
http://localhost:9000
</sonar.host.url>
</properties>
</profile>
</profiles>
I've been adding things to the POM because of different errors while trying to fix this.
I have the latest version of SonarQube installed.
Sonarqube works by analyzing jacoco outputs. I don't see any configs for jacoco in your pom. https://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/ is a good tutorial on how to set it up.
You will also have to tell sonarqube where your jacoco.exec file is at.
https://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Unit+Tests+for+Java+Project
So, the problem was that IntelliJ was configured with Java SE Development Kit 11, I downgraded to Java SE Development Kit 8u181 and configured the POM so Maven works with that change, I executed the scanner again and it worked.
Changes to pom.xml:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<sonar.sources>src/main/java</sonar.sources>
</properties>
added:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
New analysis results
Related
I have one project created which contains some reusable methods which can be used in other projects by adding it as a dependency. To do the same I have added the following in pom.xml file and when I run mvn clean deploy branch is created successfully with artifacts.
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.abc</groupId>
<artifactId>api-authenticator</artifactId>
<version>1.0.0</version>
<name>API Authenticator</name>
<description>Project to authenticate API usage</description>
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>Staging Repository</name>
<url>file://${project.build.directory}/${version}</url>
</repository>
</distributionManagement>
<properties>
<github.global.server>github</github.global.server>
<java.version>11</java.version>
<java-jwt.version>3.16.0</java-jwt.version>
<jwks-rsa.version>0.18.0</jwks-rsa.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>${java-jwt.version}</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>jwks-rsa</artifactId>
<version>${jwks-rsa.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.12</version>
<configuration>
<message>Maven artifacts for ${project.version}</message>
<noJekyll>true</noJekyll>
<outputDirectory>${project.build.directory}</outputDirectory>
<branch>refs/heads/${version}</branch>
<includes>
<include>**/*</include>
</includes>
<merge>true</merge>
<repositoryName>rwg-dip-api-authenticator</repositoryName>
<repositoryOwner>robert-walters</repositoryOwner>
<server>github</server>
</configuration>
<executions>
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<altDeploymentRepository>
internal.repo::default::file://${project.build.directory}/${version}
</altDeploymentRepository>
</configuration>
</plugin>
</plugins>
</build>
</project>
In settings.xml (Maven home: /opt/homebrew/Cellar/maven/3.8.2/libexec) I have generated personal access token with all access required and added it.
<server>
<id>github</id>
<password>access_token</password>
</server>
To use this as a dependency I have added the following in the project where I want to reuse the functions and when I do reimport the dependency from IntelliJ I can see my internal project's dependency in external dependencies But when I run the project it shows java: package com.abc.util does not exist althoght I am getting the suggestions for the class in Intellj.
<repositories>
<repository>
<id>https://github.com/me/api-authenticator</id>
<url>https://github.com/me/api-authenticator/1.0.0</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<dependency>
<groupId>com.abc</groupId>
<artifactId>api-authenticator</artifactId>
<version>1.0.0</version>
</dependency>
I have gone through the below but it was not helpful for the above case
Hosting a Maven repository on github
https://www.baeldung.com/maven-repo-github
https://dev.to/iamthecarisma/hosting-a-maven-repository-on-github-site-maven-plugin-9ch
UPDATE
As M.Deinum has suggested I have removed spring-boot-maven-plugin and now I am able to use it as depency in other projects in Intellj and it works fine locally but when the pipeline execute to create build for the project mvn package steps fails with "The POM for com.abc:api-authenticator:jar:1.0.0 is missing, no dependency information available"
If you are ok with using an external service for that, you can check https://jitpack.io/ out.
It is able to build your maven project directly from a GitHub repository and then acts as a maven repository that is serving the artifact.
It takes time to download the artifact for the first time (as it builds the project only with the first request for the artifact), but then it reuses the already built artifacts for the next requests.
Upon executing the command 'maven clean install', I get the following console screen.
My output console using m2eclipse plugin
When I visit the path mentioned in the console screen, there is only a copy of pom.xml file but not EAR and WAR file.
folder view mentioned in console
I wish to build an EAR file which contains a WAR file.
This question was posted by me today and I followed the steps as mentioned by the Gentleman.
I will also share my parent pom.xml
<artifactId>itaras</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>itaras</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<finalName>MyEarFile</finalName>
<version>5</version>
<generatedDescriptorLocation>$D:/itaras
/ITARAS_Branch_3Aug2017/itaras/WebContent
</generatedDescriptorLocation>
<modules>
<webModule>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<uri>appITARAS.war</uri>
<bundleFileName>appITARAS.war</bundleFileName>
<contextRoot>/ITARAS</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<groupId>itaras</groupId>
<profiles>
<profile>
<modules>
<module>itaras-ear</module>
<module>itaras-war</module>
<module>?</module>
</modules>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>itaras</groupId>
<artifactId>itaras-war</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
If you say <packaging>pom</packaging>, you only build a pom. Your child project needs to specify war or ear as packaging.
Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.4.4:redeploy (deploy) on project dukes-tutoring-war: Execution deploy of goal org.codehaus.cargo:cargo-maven2-plugin:1.4.4:redeploy failed: Failed to create deployer with implementation class org.codehaus.cargo.container.glassfish.GlassFish4xInstalledLocalDeployer for the parameters (container [id = [glassfish4x]], deployer type [installed]). InvocationTargetException: The container configuration directory "/home/yogesh/Downloads/glassfish4/glassfish4/glassfish/domains" does not exist. Please configure the container before attempting to perform any local deployment. Read more on: http://cargo.codehaus.org/Local+Configuration -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
After correcting the problems, you can resume the build with the command
mvn <goals> -rf :dukes-tutoring-war
my pom.xml fromdukes-tutoring-war ---------
<?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>
<artifactId>dukes-tutoring</artifactId>
<groupId>org.glassfish.javaeetutorial</groupId>
<version>7.0.5</version>
</parent>
<groupId>org.glassfish.javaeetutorial</groupId>
<artifactId>dukes-tutoring-war</artifactId>
<packaging>war</packaging>
<name>dukes-tutoring-war</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>dukes-tutoring-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${maven.exec.plugin.version}</version>
<executions>
<execution>
<id>create-tutoring-realm</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>false</skip>
<executable>/home/yogesh/Downloads/glassfish4/glassfish/bin/asadmin${glassfish.executables.suffix}</executable>
<arguments>
<argument>create-auth-realm</argument>
<argument>--classname</argument>
<argument>com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm</argument>
<argument>--property</argument>
<argument>jaas-context=jdbcRealm:datasource-jndi='java:global/TutoringDataSource':user-table=tutoring.PERSON:user-name-column=email:password-column=password:group-table=tutoring.PERSON:group-name-column=DTYPE:digest-algorithm=none</argument>
<argument>tutoringRealm</argument>
</arguments>
<successCodes>
<successCode>0</successCode>
<successCode>1</successCode>
</successCodes>
</configuration>
</plugin>
</plugins>
</build>
</project>
The pom in examples folder for <glassfish.home.prefix> settings
<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>org.glassfish.javaeetutorial</groupId>
<artifactId>javaeetutorial</artifactId>
<version>7.0.5</version>
<packaging>pom</packaging>
<name>javaeetutorial</name>
<scm>
<connection>scm:svn:https://svn.java.net/svn/javaeetutorial~svn/tags/javaeetutorial-7.0.0</connection>
<developerConnection>scm:svn:https://svn.java.net/svn/javaeetutorial~svn/tags/javaeetutorial-7.0.0</developerConnection>
</scm>
<issueManagement>
<system>IssueTracker</system>
<url>http://java.net/jira/browse/JAVAEETUTORIAL</url>
</issueManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javaee.api.version>7.0</javaee.api.version>
<maven.compiler.plugin.version>3.1</maven.compiler.plugin.version>
<maven.source.plugin.version>2.2.1</maven.source.plugin.version>
<maven.clean.plugin.version>2.5</maven.clean.plugin.version>
<maven.war.plugin.version>2.3</maven.war.plugin.version>
<maven.acr.plugin.version>1.0</maven.acr.plugin.version>
<maven.ear.plugin.version>2.8</maven.ear.plugin.version>
<maven.ejb.plugin.version>2.3</maven.ejb.plugin.version>
<maven.jar.plugin.version>2.4</maven.jar.plugin.version>
<maven.rar.plugin.version>2.3</maven.rar.plugin.version>
<maven.license.plugin.version>1.10.b1</maven.license.plugin.version>
<maven.release.plugin.version>2.4.1</maven.release.plugin.version>
<maven.exec.plugin.version>1.2.1</maven.exec.plugin.version>
<junit.version>4.11</junit.version>
<eclipselink.version>2.5.0</eclipselink.version>
<glassfish.embedded.version>4.0</glassfish.embedded.version>
<cargo.plugin.version>1.4.4</cargo.plugin.version>
<glassfish.domain.name>domain1</glassfish.domain.name>
<glassfish.home>${glassfish.home.prefix}/glassfish4</glassfish.home>
<integration.container.id>glassfish4x</integration.container.id>
</properties>
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<glassfish.home.prefix>c:/</glassfish.home.prefix>
<glassfish.executables.suffix>.bat</glassfish.executables.suffix>
</properties>
</profile>
<profile>
<id>unix</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<properties>
<glassfish.home.prefix>/home/yogesh/Downloads/glassfish4</glassfish.home.prefix>
<glassfish.executables.suffix />
</properties>
</profile>
<profile>
<id>sdk</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<glassfish.home>${basedir}/../../../</glassfish.home>
</properties>
</profile>
<profile>
<id>development</id>
<activation>
<file>
<exists>${basedir}/../bundle</exists>
</file>
</activation>
<properties>
<glassfish.home>${glassfish.home.prefix}/glassfish4</glassfish.home>
</properties>
</profile>
<profile>
<id>standalone</id>
<properties>
<glassfish.home>${basedir}/target/cargo/installs/glassfish</glassfish.home>
<cargo.maven.containerUrl>http://dlc.sun.com.edgesuite.net/glassfish/4.0/promoted/latest-glassfish.zip</cargo.maven.containerUrl>
</properties>
</profile>
</profiles>
<modules>
<module>archetypes</module>
<module>batch</module>
<module>case-studies</module>
<module>cdi</module>
<module>concurrency</module>
<module>connectors</module>
<module>ejb</module>
<module>jaxrs</module>
<module>jaxws</module>
<module>jms</module>
<module>persistence</module>
<module>security</module>
<module>web</module>
</modules>
<repositories>
<repository>
<id>snapshot-repository.java.net</id>
<name>Java.net Snapshot Repository for Maven</name>
<url>https://maven.java.net/content/repositories/staging/</url>
<layout>default</layout>
</repository>
<repository>
<id>releases-repository.java.net</id>
<name>Java.net releases Repository for Maven</name>
<url>https://maven.java.net/content/repositories/releases/</url>
<layout>default</layout>
</repository>
</repositories>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.plugin.version}</version>
</plugin>
<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-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>${cargo.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>deploy</id>
<phase>integration-test</phase>
<goals>
<goal>redeploy</goal>
</goals>
</execution>
</executions>
<configuration>
<container>
<containerId>${integration.container.id}</containerId>
<type>installed</type>
<home>${glassfish.home}</home>
</container>
<configuration>
<type>existing</type>
<home>${glassfish.home}/glassfish/domains</home>
<properties>
<cargo.glassfish.domain.name>${glassfish.domain.name}</cargo.glassfish.domain.name>
<!--cargo.remote.username></cargo.remote.username-->
<cargo.remote.password />
</properties>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>com.mycila.maven-license-plugin</groupId>
<artifactId>maven-license-plugin</artifactId>
<version>${maven.license.plugin.version}</version>
<configuration>
<header>common/license.txt</header>
<excludes>
<exclude>common/**</exclude>
<exclude>**/META-INF/**</exclude>
<exclude>**/WEB-INF/**</exclude>
<exclude>**/nbactions.xml</exclude>
<exclude>**/nb-configuration.xml</exclude>
<exclude>**/glassfish-resources.xml</exclude>
<exclude>**/simple-flow-flow.xml</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>${maven.release.plugin.version}</version>
<configuration>
<!--
During release:perform, enable the "sdk" profile
-->
<releaseProfiles>sdk</releaseProfiles>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee.api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
my glassfish4 location: /home/yogesh/Downloads/glassfish4
apache maven location: /opt/apache-maven-3.3.9
I had a similar issue when I tried to build the hello1 project, and this was mainly due to the fact that I installed Netbeans with glassfish: I suppose you did the same thing.
I'm not too sure, but it appears installing Netbeans with glassfish causes some path problems when attempting to build projects.
This is what I did to resolve it on my openSUSE Leap computer:
Stop the glassfish server if it's running and close your Netbeans IDE
Open a terminal and uninstall glassfish
cd /path/to/glassfish/installation/directory (e.g: cd ~/glassfish-4.1.1)
./uninstall.sh
Download Java EE 7 SDK Update 2 (or the latest update) from http://www.oracle.com/technetwork/java/javaee/downloads/index.html
Unzip the downloaded file (this creates the glassfish4 directory)
cd /path/to/downloaded/file/directory
unzip java_ee_sdk-7u2.zip
At this stage, the glassfish server is already installed, but it's not yet integrated in the Netbeans IDE (You will find out that it is not listed as a server in the Netbeans IDE). Instructions on how to add glassfish server as a server in Netbeans IDE can be found here: https://docs.oracle.com/cd/E19798-01/821-1770/gioew/
You can now open Netbeans IDE and try to build your project again; you should have BUILD SUCCESS as I did.
I really hope this helps.
This might also relate to the version of you glassfish server, I solved the same problem by switching to glassfish4.1.
this line in the exception message:
(container [id = [glassfish4x]], deployer type [installed])
is probably searching for the glassfish4 version,
I had this issue with guessnumber-jsf example, but it was fixed by starting my glassfish server.
I have the same problem as Junit4 and TestNG in one project with Maven but I still have issues.
I created simple project where I need to use junit4 and testng
Here is root pom:
<groupId>com.dimas.testmodule</groupId>
<artifactId>TheParent</artifactId>
<version>0.0.001</version>
<name>TheParent</name>
<packaging>pom</packaging>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
<spring.scope>test</spring.scope>
<maven.surefire.plugin.version>2.9</maven.surefire.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
...etc
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>JUnitOnly</module>
<module>TestNGOnly</module>
<module>testmodule</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<excludes>
<exclude>**/*NGTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>testNGonly</id>
<modules>
<module>JUnitOnly</module>
<module>TestNGOnly</module>
<module>testmodule</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<includes>
<include>**/*NGTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
modules JUnitOnly and TestModule just inherits and do not overrite any properties. And here are TestNgOnly
<groupId>com.dimas.testmodule.testngonly</groupId>
<artifactId>TestNGOnly</artifactId>
<version>0.0.001</version>
<name>testngonly</name>
<parent>
<groupId>com.dimas.testmodule</groupId>
<artifactId>TheParent</artifactId>
<version>0.0.001</version>
</parent>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.3.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>testNGtest</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<suiteXmlFiles>
<suiteXmlFile>
<!--test/resources/my-testng.xml-->
src\test\resources\my-testng.xml
</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Well I need to ignore testng tests for default profile and launch only testng tests for profile testNGOnly.
There are three modules - junit, testng and mixed.
The default profile should execute only junit tests - i.e. run junit module and run junit tests of mixed module. testNG profile should execute only testNG tests - i.e. run testNG module and run testNG tests of mixed module.
The way profiles work in maven, it is not possible to exclude a module in a profile. However, there is no need to build a module which is not required.
Thus, in default profile, have modules junit and mixed.
In testNG profile, add module testNG.
Following maven best practice, define <dependencies> in the parent pom within <dependencyManagement>. This allows us to only use junit dependency in junit module and testNG dependency in testNG module.
There is nothing common about surefire configuration across the three modules and as such not required to be specified in parent pom.
Since it not required to run junit tests in testNG profile, add a plugin configuration to skipTests in testNG profile for junit module.
Configure the mixed pom using the tip in this answer for the related SO question. This gets tricky since surefire needs to use junit or testng runner based on the profile.
I have incorporated the above suggestions in a sample project here.
I have a project consisting of 3 libraries - let's call them 1) BABY, 2) CHILD and 3) ADULT. Lib "CHILD" depends on "BABY" and "ADULT" depends on "CHILD".
What I want to do is produce:
a dev version that has all the (transitive) dependencies
a production version that creates a standalone JAR for each library (embedding the dependencies)
I have a profile dev and a profile release already, and I know how to use ProGuard to generate the JAR.
The question is how to tell Maven to keep all dependencies in dev and ignore them (optional/provided) in production?
To have different dependencies when you develop to deployment you could use maven profiles.
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
So when developing you would use something like mvn -Pdev compile
When you say "standalone jar" it sounds like you mean a jar with all dependencies merged into it.
How can I create an executable JAR with dependencies using Maven?
or http://maven.apache.org/plugins/maven-assembly-plugin/
Here is what I used eventually:
The parent POM defines a profile release that configurates the proguard plugin (crates one big JAR) and the install plugin (places the release artifact in the repo).
The lib-baby POM simply calls the 2 plugins in the <build> section.
The lib-child POM additionally specifies a dev profile where the dependency to lib-baby is defined. Within the release profile this dependency has an optional tag and is included in the big JAR.
In the end when run by default, the libs com.company.dev:lib-baby and com.company.dev:lib-child are created (included their dependencies).
When run with -Prelease the libs com.company:lib-baby and com.company:lib-child are created (standalone libs [WITHOUT any dependencies]) - only side effect is that the default artifacts (.*dev) are overwritten :(
parent:
<project>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
<packaging>pom</packaging>
<modules>
<module>lib-baby</module>
<module>lib-child</module>
<module>lib-adult</module>
</modules>
<profiles>
<profile>
<id>release</id>
<activation>
<property>
<name>release</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<!-- aggregate to one big jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
...
</executions>
<configuration>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-release.jar</outjar>
....
</configuration>
</plugin>
<!-- install release version of artifact separately (under com.company) -->
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>
target/${project.build.finalName}-release.jar
</file>
<groupId>com.company</groupId>
...
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
lib-baby:
<project>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
</parent>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- produces 'lib-baby-release.jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
</plugin>
<!-- installs 'lib-baby-release.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
lib-child:
<project>
<groupId>com.company.dev</groupId>
<artifactId>lib-child</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
</parent>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>release</id>
<dependencies>
<dependency>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
<version>1.0</version>
<!-- made optional because will be embedded in standalone jar -->
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<!-- produces 'lib-child-release.jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<configuration>
<assembly>
<inclusions>
<inclusion>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
</inclusion>
</inclusions>
</assembly>
</configuration>
</plugin>
<!-- installs 'lib-child-release.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>