Maven Remote Resources Plugin is not creating remote-resources.xml manifest file - java

I have a multi module Maven project which uses the same resource files across modules. I created resources project and added resources to src/main/resources folder.
This is 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.myproject</groupId>
<artifactId>project-resources</artifactId>
<version>0.0.1</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*.*</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
When I do the build, META-INF/maven/remote-resources.xml file is not created.
Am I doing something wrong?

Try:
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*</include>
</includes>
</configuration>
</plugin>
...
</plugins>
In other words: also add it to the plugins section not only the pluginManagement section.

Concerning the execution warning you are encountering - this is a known "issue" in eclipse. You can handle it through configuration goal delegation:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>bundle</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html

Related

Is there a way to fork Java VMs with Maven Failsafe plugin. I am using Junit with Serenity Runner

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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.idexx</groupId>
<artifactId>qe-lynxx-automation</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<serenity.version>2.0.27</serenity.version>
<lean.ft.version>14.50.0</lean.ft.version>
<test.directory>${project.build.testSourceDirectory}/tests</test.directory>
<tags></tags>
</properties>
<dependencies>
I have all the required dependencies but not including here.
I am unable to run test parallelly with forkCount or methods. It works fine would the sureFire plugin but I cannot use the surefire plugin to generate serenity reports.
I have tried a combination of forkCount and parallel that didn't work either.
I was able to fork multiple Java VMs using the sureFire.
I am trying to run test parallelly in multiple virtual machines. Our application is swing based java application and we are using LeanFt to automate the testing process.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<forkCount>2</forkCount>
<reuseForks>false</reuseForks>
<includes>
<!-- Run every java class in the 'tests' package -->
<include>${test.directory}/*.java</include>
</includes>
<systemPropertyVariables>
<tags>${tags}</tags>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.version}</version>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
I figured out how it actually works. All you have to do is add Surefire plugin with Failsafe plugin when you use both of them. It works like a charm.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<includes>
<!-- Run every java class in the 'tests' package -->
<include>${test.directory}/*.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<configuration>
<tags>${tags}</tags>
</configuration>
<executions>
<execution>
<id>serenity-reports</id>enter code here
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

How to Run Java class as a goal in maven after test

I have create a Java class to send a report through Email. Reports are getting generated by Maven Surfire Plugin.
Now I have a problem is test reports are not getting saved until the complete run of project. So If I called that java class in #AfterSuite , it is failing.
Is there any way to run the java class after the maven goal?
<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>SoapOCPAutomation</groupId>
<artifactId>SoapOCPAutomation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SoapOCPAutomation</name>
<description>SoapOCPAutomation</description><repositories>
<repository>
<id>smartbear-sweden-plugin-repository</id>
<url>http://www.soapui.org/repository/maven2/</url>
</repository>
</repositories>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
<forkCount>0</forkCount>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>send-report</id>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.acxsys.ocp.api.emt.ks.report.KSSendEmail</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
You can use maven-exec plugin with java goal:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>send-report</id>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>your.reporting.Class</mainClass>
</configuration>
</plugin>
</plugins>
</build>
When you do mvn package or mvn install, this will execute your reporting class in package phase, which comes after surefire plugin execution.

How to generate client code using with swagger-codegen-plugin (maven)?

I need to generate a server stub code in eclipse using with swagger-codegen-plugin (for maven) . can you please help how to do it ? and what configuration needed for that( in pom.xml).
I found this answer. You just need to change pom.xml like below.
pom.xml.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<version.swagger.codegen>2.2.1</version.swagger.codegen>
<yaml.file>${project.basedir}/src/main/resources/Api.yaml</yaml.file>
<generated-sources-path>${project.build.directory}/generated-sources</generated-sources-path>
<generated-sources-java-path>main/java</generated-sources-java-path>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${version.swagger.codegen}</version>
<configuration>
<inputSpec>${yaml.file}</inputSpec>
<configOptions>
<sourceFolder>${generated-sources-java-path}</sourceFolder>
</configOptions>
<output>${generated-sources-path}</output>
</configuration>
<executions>
<execution>
<id>generate-swagger-spring</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<language>spring</language>
<modelPackage>${project.groupId}.swagger.model</modelPackage>
<apiPackage>${project.groupId}.swagger.api</apiPackage>
<invokerPackage>${project.groupId}.swagger.invoker</invokerPackage>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-generated-source</id>
<phase>initialize</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${generated-sources-path}/${generated-sources-java-path}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<versionRange>[${version.swagger.codegen},)</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<!-- Swagger -->
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>contract-service</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${basedir}/src/main/resources/swagger/rest-data-exchange-format.yaml</inputSpec>
<artifactId>contract-service</artifactId>
<output>${basedir}/target/generated-sources</output>
<language>spring</language>
<modelPackage>ru.payhub.rest.v1.model</modelPackage>
<apiPackage>ru.payhub.rest.v1.api</apiPackage>
<!-- <invokerPackage>ru.payhub.rest.v1.handler</invokerPackage> -->
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<library>spring-boot</library>
<dateLibrary>${generator.datelibrary}</dateLibrary>
<configPackage>ru.payhub.config</configPackage>
<singleContentTypes>true</singleContentTypes>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Official parametrs description here
Swagger syntax specification here
On this example maven plugin, used swagger data-model file (yaml) generate model classes for use it in the controllers.
Sample configuration for swagger-codegen-maven-plugin is available at https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen-maven-plugin
List of possible languages is available here: https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages

maven project which has both java and scala

I want to build a maven project which has both java and scala source code.
I have installed scala IDE plugin in eclipse and added the "scala-maven-plugin" in pom.xml but the imports of java classes in the scala files are giving compilation errors.
Which is the best IDE to build such mixed projects?
The project structure is
The 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>org.apache.spark</groupId>
<artifactId>spark-examples_2.11</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.7</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!-- This plugin compiles Scala files -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plugin compiles Java files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plugin adds all dependencies to JAR file during 'package' command.
Pay EXTRA attention to the 'mainClass' tag.
You have to set name of class with entry point to program ('main' method) -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>ScalaRunner</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
It seems from your code structure that your Scala classes depend on Java, not the other way around. Yet in your Maven config, Scala gets compiled first. Change it to compile after Java classes.
The following plugin sequence works in my project:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Its safest to go straight to the page provided by the scala-maven-plugin docs where you can find the current pom definition which supports dependencies in both directions

Maven toolchain not getting triggered in build

I'm using the latest maven 3.3.9 which enforces java 8, and trying to compile a project in java 7 using a java 7 maven toolchain.
As per: The maven guide I've put in the maven toolchain plugin to try and tell it to use java 7 to compile the app. My project setup is as follows:
top_module --> (have put in maven toolchain plugin in this pom.xml)
---submodule1
---submodule2
This is my 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>
<parent>
<groupId>parent</groupId>
<artifactId>build-base</artifactId>
<version>1.0.17</version>
</parent>
<groupId>top_module</groupId>
<artifactId>top_module</artifactId>
<version>1</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<modules>
<module>submodule1</module>
<module>submodule2</module>
</modules>
<properties>
...
</properties>
<dependencyManagement>
<dependencies>
<dependency>
...
</dependency>
<dependency>
...
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
...
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!-- Ensure we compile as the correct jdk version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.7</version>
<vendor>sun</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
<!-- Maven WAR Plugin -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
<inherited>true</inherited>
<configuration>
<archiveClasses>true</archiveClasses>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
...
</project>
The build doesn't run any toolchain related steps and conks out when running mvn clean install due to a plugin being incompatible with java 8, which obviously means the toolchain isn't getting run. Do I need anything else in the pom?
This is my toolchains.xml file in my M2_HOME:
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<!-- JDK toolchains -->
<toolchain>
<type>jdk</type>
<provides>
<version>1.6</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>C:\Java\jdk1.6.0_45</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>1.7</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>C:\Java\jdk1.7.0_79</jdkHome>
</configuration>
</toolchain>
</toolchains>
The problem is simply related that you have defined all plugins in pluginManagement but you need to define them like this:
<build>
<pluginManagement>
<plugins>
<!-- Ensure we compile as the correct jdk version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
</plugin>
<!-- Maven WAR Plugin -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
<inherited>true</inherited>
<configuration>
<archiveClasses>true</archiveClasses>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
<configuration>
<toolchains>
<jdk>
<version>1.7</version>
<vendor>sun</vendor>
</jdk>
</toolchains>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
pluginManagement is intended to define versions and default configurations but no binding to the lifeycle which you need to do for the maven-toolchains-plugin. In pluginManagement you should define all plugins which their versions which you are using which means maven-resources-plugin, maven-install-plugin, maven-deploy-plugin, maven-enforcer-plugin etc. This might be a good candidate for a corporate parent pom which defines all those things.
And you are going the best way to separate the JDK which is used by Maven and the JDK which is used by your code.
Apart from that Maven 3.3.9 needs JDK 7 as minimum and not JDK 8
If you just want maven to use the java 7 jdk all the time, the toolchain plugin may be more than you need. it may be enough to set JAVA_HOME
Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.7.* and that $JAVA_HOME/bin is in your PATH environment variable. ( Or if from eclipse, set it as the workspace default )
If you want to switch jdk from just 1 project, you can also use the compilerVersion tag
https://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

Categories

Resources