Package com_atlassian_clover is not visible - maven

I am experimenting with java modules and unit tests.
So I also have the clover plugin within my maven pom.xml:
<plugin>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>4.2.0</version>
<configuration>
<excludes>
<exclude>**/module-info.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
But when running
mvn clover:instrument
I got the following error:
error: package com_atlassian_clover is not visible
(package com_atlassian_clover is declared in the unnamed module, but module com_atlassian_clover does not read it)
How could I fix that? Or do I have to wait until clover will support java modules?
I think it would be not a good idea to include the clover package within my modules-info.java. (Might be a solution, because clover instruments the code).

Related

Maven shade plugin how to add package level resources

I am using shade plugin to build a fat or uber jar . Please see my shade plugin pom snippet as below
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
I have some resource file for XML and properties which are not in src/main/resources but lies along with java packages.
When I build the code with maven with mvn clean package it compiles and add all dependent jar file but all resources files that are at the package level say src/main/java/x/y/z/hibernate.hbm.xml doesnt get added into respective place of fat jar.
Could someone please let me know what extra I have to do in above maven snippet to add those resources
I tried adding . in the artifacts set it didn't work . Also using maven assembly plugin its not working. I also searched direct eclipse plugin which can help but no clue. please help

IT code coverage with sonar

I have the following task at hand:
-- find IT code coverage for a project
Given situation:
-- IT code resides in a repository separate to the actual production code
-- Production code that the tests were created for reside in more than one git repository.
-- all of the above uses maven and are written in Java.
I have tried following different tutorial and blogs but couldnt find a simpler answer.
Can anyone either point me towards the right resource or give me hints for a kick start?
I will try to answer. I will post example with UT (IT is the same thing just not at the same place in the maven livecycle build, and instead of the surefire plugin its the failsafe plugin)
Lets say we use JaCoCo for the code coverage agent.
In my Parent pom, in the profile section (it is a multi module project)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<argLine>${surefireArgLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.4.201502262128</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Now when we build our maven project, we add the profile to inject the JaCoCo Agent
clean install -Psonar-coverage
Then we may tell sonar to analyse our project and to use the JaCoCo report with the following command
mvn org.codehaus.mojo:sonar-maven-plugin:2.4:sonar -Dsonar.dynamicAnalysis=reuseReports -Dsonar.java.coveragePlugin=jacoco -Dsonar.forceAnalysis=true -Dsonar.jacoco.reportMissing.force.zero=true -Dsonar.binaries=target/classes -Dsonar.junit.reportsPath=target/surefire-reports -Dsonar.jacoco.reportPath=target/coverage-reports/jacoco-ut.exec -Dsonar.jdbc.driver=com.mysql.jdbc.Driver -Dsonar.jdbc.url=jdbc:<YOUR SONAR INSTALLATION DB> -Dsonar.host.url=<YOUR SONAR INSTALLATION>

How Exclude Plugin from integration-test in Eclipse RCP / Maven

I have an application which use the Eclipse RCP. I have severals plugins, they each have a pom.xml file, and all the project has a super pom.xml.
The structure is :
plugin.a ( pom.xml inside )
plugin.b ( pom.xml inside )
plugin.c ( pom.xml inside )
plugin.test ( with a pom.xml too, contains all JUnit tests classes )
pom.xml
My problem is, when i launch the command : mvn integration-test
Maven tries to execute all *Test.java, but if it doesn't find it crashes ( for example in plugin a / b / c ).
How exclude specifics plugins to avoid this compilation error ?
Thank you in advance.
Edit : I found. In Each pom.xml, i was in <packaging>eclipse-test-plugin</packaging> and no in <packaging>eclipse-plugin</packaging> if i want to avoid compilation error in non tests plugins.
But thank you for help guys. <3
You can distinguish which tests run in which phase using both the surefire plugin (Unit Testing) and the failsafe plugin (Integration Testing)
As an example: (in parent pom.xml)
In your case I would think you need a similar configuration in every plugin module if there is no common pattern across the modules. So you can disable the execution per plugin.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<forkMode>once</forkMode>
<includes>
<include>**/Test*.java</include>
</includes>
<excludes>
<exclude>**/*</exclude>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>failsafe-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</plugin>
If there is a common pattern but you want to just disable the execution you can add an execution to the plugin, giving it an id. A child pom can then re-configure that execution if it uses the same id
<plugin>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<configuration>
</configuration>
<executions>
<execution>
<id>test-run-thing-id</id>
<phase>install</phase>
<goals>
<goal>plugin-goal</goal>
</goals>
</execution>
</executions>
</plugin>

Can't run test via maven with a package-info.java file in the same package as the Test Case Class

The strangest thing ever occurred today when I was running a simple test class via Maven. From within the Eclipse IDE there is no problem what so ever.
My package has one JUnit Test Case Class and a package-info.java documentation class.
I found that the package-info.java somehow interferes with the Maven compiler plugin. When removed the test runs fine.
When the package-info.java exists in the package Maven writes this in the log:
[ERROR] Failure executing javac, but could not parse the error:
javac: invalid source release: **/*.java
Usage: javac <options> <source files>
use -help for a list of possible options
How can I make Maven skip the package-info.java so that I can keep it in the package folder?
I had the exact same problem a few days back and solved it by entering this in my pom.xml file:
<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>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>1.6</source>
<target>1.6</target>
<testSource> **/*.java</testSource>
<testExcludes>
<exclude>**/package-info.java</exclude>
</testExcludes>
</configuration>
</execution>
</executions>
</plugin>
It is the testExcludes element that makes Maven forget the package-info.java class.

Maven pluginManagement configuration inheritance strange behavior

I'm using pluginManagement element in my parent pom.xml to configure plugins for all its children. For example, I have the following configuration:
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>copy-artifacts</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>some/where/else</outputDirectory>
<resources>
<resource>
<directory>some/another/resource</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>deps/dir</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</pluginManagement>
The official documentation states that a plugin configured in pluginManagement still has to be added to plugins element in children poms. Indeed, if I remove this from child pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
then maven-dependency-plugin stops firing at install phase. However, it seems that it does not affect some other plugins, namely, maven-resource-plugin. Even if I do not have
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
in my child pom, its copy-resources goal still fires at install phase and performs the work it is configured to do.
Why is this behavior present? Is there a list of plugins which are inherited always, or maybe I'm missing something?
The whole POM isn't visible; but given the behavior you're describing this is a jar, war, or ear, correct? The resource plugin is defined for those packaging types by default. It includes an execution that copies resources (as described by #maba).
Since the plugin definition is included in your child POM (even though YOU didn't put it there directly), Maven merges the execution defined in the <pluginManagement> section with the execution provided by Maven.
There is documentation describing the default lifecycle bindings by packaging type. Note the dependency plugin isn't mentioned; but resources is; that's why you observe the difference. Running with -X will show the plugin executions.
Maven always copies resources that are inside src/main/resources by default.
From Maven Getting Started Guide:
The simple rule employed by Maven is this: any directories or files placed within the ${basedir}/src/main/resources directory are packaged in your JAR with the exact same structure starting at the base of the JAR.

Resources