Difference between v2.18 and v2.22.0 of Maven surefire plugin - maven

I configured surefire v2.18 to exclude tests in packages like e2e.com.mycompany.myapp but not like com.mycompany.myapp.e2e and it was working but if I use v2.22.0 I get a different behavior: both are excluded. Is it a bug?
My configuration is:
<configuration>
<excludes>
<exclude>e2e/**</exclude>
</excludes>
</configuration>
I also tried with:
<configuration>
<excludes>
<exclude>e2e/**/*Test*.java</exclude>
</excludes>
</configuration>
How can I get the same behavior with the new version? I'm using Maven 3.3.9.

You could go through following link which explains enhancements made with v2.19 onwards for exclusion and inclusion of tests:
https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
Following is brief snapshot captured from above link for inclusion and exclusion of packages and classes:
Following link explains release notes for v2.22:
https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=12317927&version=12343425

Related

Maven : exclude target/generated-sources from compilation

This question, just to be sure my interpretation is correct :
I'm using Mojohaus jaxb2-maven-plugin to generate java classes from .xsd files, and by default it puts them in target/generated-sources
Now, I want to get track of these classes in source control (target is of course excluded), and I may one day slightly customize one with an annotation or a line of code, and I may even change my class generation plugin, so what do is I copy these classes and packages in src/main/java
This upsets Maven when I try to compile because he considers "target/generated-sources" as a source directory and he finds all clases twice. For what I understand, I can exclude classes inside a source directory, but I can't remove a source directory from Maven build, am I right ?
So the only solution would be to configure my jaxb2 plugin to generate the classes elsewhere, right ?
UPDATE :
Ok, this doesn't work as I thought, if I change the outputDirectory of my jaxb plugin, it's still included as a source directory by Maven, and I have no clue why.
<configuration>
<outputDirectory>${project.build.directory}/tatata/jaxb</outputDirectory>
</configuration>
UPDATE 2 : The explanation is the plugin is adding the outputDirectory as a maven source directory during the generate-sources phase of the build, and it's not optionnal or customizable.
First things first, do not add generation code to source control. Do not modify it manually. You will get into trouble. Believe me, I've seen it too many times. A new version of the schema and you're lost.
Ok, now to your question.
With maven-jaxb2-plugin you could turn off adding generation directory as a compile source root with:
<configuration>
<addCompileSourceRoot>false</addCompileSourceRoot>
</configuration>
Disclaimer: I'm the author of maven-jaxb2-plugin.
The answer from Lexicore is an interesting lead but my question was about the plugin I'm currently using, not how to do it with an other plugin.
So here is the workaround for the Mojohaus plugin : you can just skip the generate-sources by default (no need to do this task at every build when your model changes once in a week, then once in a year), and trigger it only when needed using a dedicated maven profile : How to skip generate-sources in Maven
you can always specify the target directory(generateDirectory) in pom config file as below. Hope it helps
`
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generateDirectory>${basedir}/src/main/java</generateDirectory>
<generatePackage>com.myproj.proxy</generatePackage>
<schemas>
<schema>
<!-- <url>${project.basedir}/src/main/resources/wsdl/test.wsdl</url> -->
<fileset>
<!-- Defaults to schemaDirectory. -->
<directory>${basedir}/src/main/resources/wsdl</directory>
<!-- Defaults to schemaIncludes. -->
<includes>
<include>*.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</plugin>
`

How to run test sequentially with Maven surefire

After searching everywhere on internet I post my question here for an possible answer. First of all, sorry for my bad English, I'm a French speaker.
I'm trying to run Java tests in my Jenkins for a continuous integration project. But Maven run the tests in parallel. The First 10 tests need to be runned sequentially because they initialize database and some templates.
I found this link on the official page : https://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html
but when I use #NotThreadSafe on my Java test class as they said I got an error :
error: cannot find symbol
could not parse error message: symbol: class NotThreadSafe
I use Maven 2.2.1, Junit 4.6
Do you know how could I do please ?
Edit : my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/P99ReleaseTestSuite.java</include>
</includes>
<!--
<excludes> <exclude>**/*Test.java</exclude> </excludes>
-->
<skipExec>${surefire.tests.execution.skip}</skipExec>
<testFailureIgnore>${surefire.tests.execution.ignore-error}</testFailureIgnore>
<forkMode>once</forkMode>
<argLine>-Xms512m -Xmx2048m</argLine>
</configuration>
</plugin>
I run these tests in a linux server. On windows, in my eclipse, all tests run sequentially

How to access maven.build.timestamp for resource filtering

I am using maven 3.0.4 and would like to make the build timestamp accessible to my application. For this, I'm putting a placeholder in a .properties file and let maven filter on build. While this is working fine for ${project.version}, ${maven.build.timestamp} is not substituted on filtering.
The property seems to be available on build - I can use it to modify the artifact name:
<finalName>${project.artifactId}-${maven.build.timestamp}</finalName>
So why is it not available for resource filtering? And, more importantly, how do I make it accessible?
I have discovered this article, explaining that due to a bug in maven, the build timestamp does not get propagated to the filtering. The workaround is to wrap the timestamp in another property:
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
</properties>
Filtering then works as expected for
buildTimestamp=${timestamp}
I can confirm as of Maven 3.x {maven.build.timestamp} is "working" now. They work arounded the problem, apparently. No additional properties workaround needed anymore.
However, be careful your "filtering" plugin (maven-resources-plugin) is up to date. It needs to be relatively new, so if mvn help:effective-pom shows an old version (ex: 2.6), bump it to something newer, fixed it for me, 3.x ex:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<properties><timestamp>... workaround is no longer required...
This also cleared up, kind of, why it was working in IntelliJ but not the command line. IntelliJ probably uses their own "modified/internal" maven constants, so it was working there, but not from maven command line.
Also note if you add a filtering resource directory to you pom, you may need to also "re-add" the default directory, it gets lost, ex:
<resource>
<directory>src/main/resources-filtered</directory> <!-- to get "maven.build.timestamp" into resource properties file -->
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory> <!-- apparently have to add this is you have the other... -->
</resource>
NB if you're using spring boot as your parent, you have to use #maven.build.timestamp# instead. Also note if you're using spring boot there's a file META-INF/build-info.properties that is optionally created by the spring-boot-maven-plugin that you can read (spring provides a BuildProperties bean for convenience reading it).
In order to enrich the Stackoverflow content for others, that like me, found this post as a way to solve the "problem" of ${maven.build.timestamp}. This is not a maven bug, but an expected behavior of m2e, as can be seen in this post.
Therefore, I believe that we can not expect the solution to be "corrected", since, from what I understand, the correction involves conceptual issues.
In my case, what I did was use the plugin (buildnumber-maven-plugin) as described in this other post.
Adding Maven properties at the pom project level doesn't take into account correct local Timezone, so timestamp may appear wrong :
<properties><timestamp>${maven.build.timestamp}</timestamp></properties>
Using the build-helper-maven-plugin applies the correct timezone and current daylight saving to the timestamp :
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>timestamp-property</id>
<goals>
<goal>timestamp-property</goal>
</goals>
<configuration>
<name>timestamp</name>
<pattern>yyyy-MM-dd HH:mm:ss</pattern>
<timeZone>Europe/Zurich</timeZone>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
When packaging, Maven will replace any token timestamp in /resources folder, e.g. resources/version.properties :
build.timestamp=${timestamp}
You can then load this properties file in your Application.

InstalledFileLocator on a NetBeans Maven platform project

I'm trying to figure out where/how do I create the equivalent of the release folder on ANT project so my Maven application can find files in it using InstalledFileLocator.
I found http://mojo.codehaus.org/nbm-maven/nbm-maven-plugin/nbm-mojo.html#nbmResources but I can't make it work. I tried in the application, a module, etc without luck.
Any hints?
Edit:
Code can be found here in the Marauroa-Server-Manager folder.
This is how it was done:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
...
<nbmResources>
<nbmResource>
<directory>${basedir}/resources</directory>
<targetPath>resources</targetPath>
<includes>
<include>*.gif</include>
</includes>
</nbmResource>
</nbmResources>
...
</configuration>
</plugin>
In my case, I was missing the nbmResources tags surrounding the nbmResource element.

maven 3 javadoc plugin doesn't take the excludepackagename config

I'm trying to exclude a bunch of packages from a javadoc site.
Unfortunately this plugin seems to live its own life and when it was configured as a report plugin it failed with access denied when moving files, so it was changed to be a normal plugin and then configured to run with the site goal (aggregated). By doing that we have the javadoc generated and it's published under the site as it should be.
But it seems that the configuration parameters for the plugin doesn't take effect at all. I've tried to move the <excludePackageNames> element around - both being a general config and to be a specific config for the aggregate goal - and I even added an exclusion for our entire code base and all files was still generated.
What I'm trying to do is to simply remove a couple of packages that shouldn't be in the javadoc. Anyone who got this plugin and the config to play nicely, to exclude packages?
This is the config I use right now, the javadoc is created but all packages, including the excluded, is generated.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<excludePackageNames>my.company.packages.*</excludePackageNames>
</configuration>
<executions>
<!-- Hook up the Javadoc generation on the site phase -->
<execution>
<id>aggregate</id>
<goals>
<goal>aggregate</goal>
</goals>
<phase>site</phase>
</execution>
</executions>
</plugin>
Any ideas, pretty please?
I solved identical problem by adding the sourcepath parameter to the configuration:
<configuration>
<sourcepath>${project.basedir}/src/main/java</sourcepath>
<excludePackageNames>my.company.packages.*</excludePackageNames>
</configuration>
The configuration above will exclude all packages below my.company.packages but not my.company.packages itself. To exclude also my.company.packages use <excludePackageNames>my.company.packages</excludePackageNames> instead.

Resources