Maven Copy Files and Folders Plugin not copying linux [dot] ".*" hidden files - linux

I have a maven code
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources-from-parent</id>
<phase>initialize</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>./target/aut-ws</outputDirectory>
<resources>
<resource>
<directory>/prj//workspace-Fm-aut-Testing/</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
This is working fine, but it is not copying .* linux files which are hidden. In normal linux we would use a parameter -a. How to use this here?
Thanks
Jeevan

To disable this behaviour set addDefaultExcludes to false.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<addDefaultExcludes>false</addDefaultExcludes>
</configuration>
</plugin>
By default files like .gitignore, .cvsignore etc. are excluded which
means they will not being copied. If you need them for a particular
reason you can do that by settings this to false.
Documentation: https://maven.apache.org/plugins/maven-resources-plugin/copy-resources-mojo.html#addDefaultExcludes

In my case ".file" was in target/[unpacked folder] but was missing in final .jar.
I achieved this adding maven-antrun-plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<configuration>
<target>
<echo message="repackaging" />
<jar destfile="${project.build.directory}/${project.build.finalName}.jar" basedir="${project.build.directory}/${project.artifactId}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

Related

Karate tests in other folder than src/test

I want to move Karate tests from src/test to a new folder src/it because it makes sense to me to have integration tests separated from unit tests.
Is that possible?
I tried to put java classes in src/it/java and features in src/it/resources and Karate tests run, but without test cases.
Thanks in advance.
Issue was solved using a Maven plugin to add src/it/java as test sources and src/it/resources as test resources:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-test-source</id>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-resource</id>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/it/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

jaxb2-annotate-plugin: Adding annotations to the XJC classpath

Is it possible to add custom annotations to the XJC classpath, while they are defined within my project itself? This when using the maven jaxb2-annotate-plugin.
The problem regards this piece of the documentation:
Annotation classes must be known in compile time. I.e. annotation classes must be made available in the XJC classpath. If you want to use your own annotations, you have to pre-compile them and add your annotation classes to the XJC classpath.
When I make a seperate project and add it to the plugin, it works fine as shown in the documentation examples.
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<id>generate</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<args>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>1.0.2</version>
</plugin>
<plugin>
<groupId>com.acme</groupId>
<artifactId>external-project</artifactId>
<version>1.0.0</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>
But I'd like to use the annotation that resides in the same project. How do I let it get picked up? If I compile it in a stage before process-resources, with the following piece:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>compile</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
The class gets compiled before the generation from my XSD's, but I still get the exception AnnotationClassNotFoundException. I'd like to avoid making seperate projects and/or modules just for adding annotations. How come it can't find my classes and the only way to provide annotations seems to be external projects/modules?
I have found the solution to my problem.
When configuring the maven-jaxb2-plugin plugin, it's possible to provide dependencies for that plugin. When providing my own project as the dependency, it can find the classes for it. So the following works out:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.1</version>
<executions>
<execution>
<id>generate</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<args>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>1.0.2</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>current-project</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
It is required for your annotations to be compiled beforehand however. So to compile it beforehand, the following plugin should be added before the maven-jaxb2-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>process-resources</phase>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
The problem with that is the first time of mvn clean install.
What if you haven't compiled it yet? For example go to your .m2 or mavel-local-repo and cancel your project and then do mvn clean install and see if it fails

JAXB2 maven plugin in eclipse shows error

I'm using JDK 1.6 (due to dependencies) and to generate classes from xsd, I have added maven-jaxb2 plugin as shown below in pom.xml.
But the eclipse (Kepler) complains as below.
Error parsing the command line [[-Xsimplify, -episode,
D:\test\workspace\sample\target\generated-sources\xjc\META-INF\sun-jaxb.episode]]
(org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.8.1:generate:jaxb-test:generate-sources)
pom.xml
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.9.0</version>
<executions>
<execution>
<id>jaxb-test</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<forceRegenerate>true</forceRegenerate>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>sample.xsd</include>
</schemaIncludes>
<xjbSources>
<xjbSource>bindings.xjb</xjbSource>
</xjbSources>
</configuration>
</execution>
</executions>
<configuration>
<extension>true</extension>
<args>
<arg>-Xsimplify</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.0</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
Try to upgrade to maven-jaxb2-plugin 0.13.1, and jaxb2-basics 0.11.0.
The versions you have now are very old already.

How to target maven executions to the build folder only?

I have a project using Maven and the frontend-maven-plugin (com.github.eirslett).
As I run mvn install all the executions from the plugin run, and they create a node_modules, bower_components, and node folders in the src/main/webapp root, where the actual frontend code is.
The thing is, I wanted to mvn install only execute and create those in war the package generated in the build directory, not in the versioned application code, just like it does with Java libraries.
Is there a way to achieve that?
This is the relevant part of my pom.xml:
<build>
<directory>build</directory>
<outputDirectory>build/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
<includes>
<include>WEB-INF/weblogic.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
...
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.20</version>
<configuration>
<workingDirectory>src/main/webapp</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v0.10.34</nodeVersion>
<npmVersion>2.1.11</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>bower install</id>
<goals>
<goal>bower</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
It's possible to use <installDirectory> configuration parameter to choose where to install NodeJS.
frontend-maven-plugin will install node_modules in the place where it founds package.json. That's why you need to provide copy of your web resources with package.json to some target/<sub-path>.
Then frontend-maven-plugin may be configured by this way:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.24</version>
<configuration>
<nodeVersion>v0.11.14</nodeVersion>
<npmVersion>2.13.4</npmVersion>
<installDirectory>target/<sub-path></installDirectory>
<workingDirectory>target/<sub-path></workingDirectory>
</configuration>
...
The plugin (frontend-maven-plugin) mostly supports this. The "workingDirectory" parameter tells plugin where to do the work (i.e. npm install). That requires though that the build files (i.e. package.json, gruntFile.js) be in that workingDirectory. To accomodate this I added a antrun execution to copy those files over (with filtering) before the rest of the build. My grunt file then references the files from source when appropriate and any output goes in my target-grunt folder.
Here is my config:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.20</version>
<configuration>
<workingDirectory>target-grunt</workingDirectory>
</configuration>
<executions>
...
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>prepare-grunt</id>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- copy, filter, rename -->
<filter token="moduleName" value="${moduleName}" />
<filter token="project.version" value="${project.version}" />
<filter token="project.artifactId" value="${project.artifactId}" />
<copy file="${basedir}/target-grunt/imported-js/main/js/com/verisk/underwriting/config/grunt/npm-package-module/0.0.1/npm-package-module-0.0.1.js" tofile="${basedir}/target-grunt/package.json" filtering="true" failonerror="true" verbose="true" />
<copy file="${basedir}/Gruntfile.js" tofile="${basedir}/target-grunt/Gruntfile.js" failonerror="true" verbose="true" />
</target>
</configuration>
</execution>
</executions>
</plugin>
A possible way in order to do not dirty the frontend resources dir, contained as example in src/main/frontendResources, coming from GIT (or another source repo) with the node_modules, bower_components, ..., directories and files generated during npm, bower and grunt execution is:
using maven-resources-plugin, copy the sources directory src/main/frontendResources
in /target/webappStagingDir subfolder during
initialization phase
set the workingDirectory and
installDirectory in frontend-maven-plugin to /target/webappStagingDir
set the bower output directory as
subfolder of /target/webappStagingDir. In example put
{"directory":
"bower_components"}
in .bowerrc file
after bower build, using
maven-resources-plugin, copy the output built sources contained in
bower_components folder to /target/${artifactId}-${version} during
prepare-package phase (before war building)
Here is the pom slice:
...
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<workingDirectory>${basedir}/target/frontendResourcesStagingDir</workingDirectory>
<installDirectory>${basedir}/target/frontendResourcesStagingDir</installDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<phase>generate-resources</phase>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v8.12.0</nodeVersion>
<npmVersion>6.4.1</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<phase>generate-resources</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>bower install</id>
<phase>generate-resources</phase>
<goals>
<goal>bower</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<phase>generate-resources</phase>
<goals>
<goal>grunt</goal>
</goals>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<!--
Copy of the /frontendResources directory, coming from GIT, in /target directory
executed before the compiling and build of frontend resources
That dir will be the working directory of npm, bower, grunt
in order to avoid the creation of the direcotries node, node_modules, bower_components, ...
(they may be committed in repository)
-->
<execution>
<id>copy-frontendResources-toStagingDir-beforeBuild</id>
<phase>initialize</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/frontendResourcesStagingDir</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/frontendResources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<!--
Copy of the /frontendResourcesStagingDir/grunt_output directory in /target/ directory
executed after build of frontend resources and before the war pachage creation
it contains the output of grunt install execution
-->
<execution>
<id>copy-frontendResources-afterBuild</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/${artifactId}-${version}</outputDirectory>
<resources>
<resource>
<directory>${basedir}/target/frontendResourcesStagingDir/grunt_output</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
...
This solution is useful also for mixed projects with frontend in Node.js and backend in Java that has a single .war file as output deliverable

Sonar build does not run Cucumber tests

I am trying to run Sonar build on Jenkins. My project contains both Junit and Cucumber tests. I verified the log files after build, the Sonar build kicks off after normal maven build and picks only the Junit tests but not Cucumber tests.
I have the following versions and plugins available in my POM file. Please let me know if any one has come across the similar issue and fixed it. Many Thanks!
Junit version 4.11
Cucumber version 1.1.2
Sonar version 3.5.1
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<id>start-jetty</id>
<phase>process-test-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>prepare-package</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<stopPort>8999</stopPort>
<stopKey>STOP</stopKey>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8997</port>
<maxIdleTime>3600000</maxIdleTime>
</connector>
</connectors>
<systemProperties>
<systemProperty>
<name>dqs.env</name>
<value>local</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*RunDQSWsTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*RunDQSWsTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
RunDQSWsTest.java is the main file which runs all the .feature files

Resources