Maven duplicate class with generated sources when using -f option - maven

I try to build a Maven project with classes generated from jaxb2-maven-plugin.
Consider the following minimal 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>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>test</packageName>
<sources>
<source>src/main/resources/schema.xsd</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And this minimal schema in src/main/resources/schema.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" vc:maxVersion="1.1" vc:minVersion="1.0" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root" type="xs:string"/>
</xs:schema>
When invoking mvn clean compile, the project is built as expected. But when I specify the file using a path containing .., the following error occurs. When using a (relative or absolute) path without .., everything is fine.
C:\dev\test>mvn -f ..\test\pom.xml clean compile
[...]
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test: Compilation failure: Compilation failure:
[ERROR] /C:/dev/test/target/generated-sources/jaxb/test/ObjectFactory.java:[32,8] duplicate class: test.ObjectFactory
How can I get rid of this error and build my project using mvn -f <some path containing "..">?

For me (on macOS), the issue goes away when I don't have a "." component in my path:
maven compile -f ./blah/blah # <-- "duplicate class" errors
maven compile -f blah/blah # <-- works fine
Ugly workaround: Try using an absolute path?
(Seems like a path normalization bug in Maven or maven-compiler-plugin.)

Related

get error when i try to consume spec openapi in service project backbase

I'm following A tutorial in backbase academy exactly in chapter "Backbase Backend Essentials Course - Service SDK and Direct Integration Services" and i get error when i try to consume specification from service project , this is the error
exchange-rate-service: Compilation failure: Compilation failure:
symbol: method requiredMode()
[ERROR] location: #interface Schema
and this is my pom.xml of spec project
<?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>com.backbase.buildingblocks</groupId>
<artifactId>backbase-openapi-spec-starter-parent</artifactId>
<version>11.3.0</version>
</parent>
<groupId>com.backbase.training</groupId>
<artifactId>exchange-rate-specification</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Backbase :: Exchange Rate Specification</name>
<properties>
<!-- plugin versions -->
<boat-maven-plugin.version>0.4.0</boat-maven-plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.backbase.oss</groupId>
<artifactId>boat-maven-plugin</artifactId>
<version>${boat-maven-plugin.version}</version>
<executions>
<execution>
<id>boat-validation</id>
<phase>generate-sources</phase>
<goals>
<goal>validate</goal>
</goals>
<configuration>
<input>${project.basedir}/src/main/resources/openapi.yaml</input>
<failOnWarning>true</failOnWarning>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
even with this project i get the same error
https://github.com/Backbase/documentation-code-samples/tree/master/service-sdk/11.0.0/create-openapi-spec-project
these is the steps that i followed :
1.download project from github
2.run cmd "mvn clean install" on project "messaging-api"
until now i get BUILD SUCCESS
3. run cmd "mvn clean install" on project "messaging-service"
i get this error
ErrorItem.java:[67,3] error: cannot find symbol
symbol: class Schema
location: class ErrorItem

How to trigger a Tomcat source build using maven?

in my project I would like to compile tomcat 10.0.14 sources from pom.xml of my project. How can I run ant to compile tomcat sources inside maven for my purpose?
I tried with maven-antrun-plugin
<?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>
<groupId>it.atlantica</groupId>
<artifactId>tomcat</artifactId>
<version>10.0.14</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>build-tomcat</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<ant antfile="${basedir}/build.xml" target="deploy"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
but I have this error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:3.0.0:run (build-tomcat) on project tomcat: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] /root/sam/tomcat-10.0.14/build.xml:978: Unable to find a javac compiler;
[ERROR] com.sun.tools.javac.Main is not on the classpath.
[ERROR] Perhaps JAVA_HOME does not point to the JDK.
[ERROR] It is currently set to "/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64/jre"
[ERROR] around Ant part ...<ant antfile="/root/sam/tomcat-10.0.14/build.xml" target="deploy" />... # 4:73 in /root/sam/tomcat-10.0.14/target/antrun/build-main.xml
If I set JAVA_HOME, instead I have other errors:
/root/sam/tomcat-10.0.14/java/org/apache/catalina/ant/AbstractCatalinaCommandTask.java:22: error: package org.apache.tools.ant does not exist
import org.apache.tools.ant.BuildException;
^
/root/sam/tomcat-10.0.14/java/org/apache/catalina/ant/BaseRedirectorHelperTask.java:47: error: cannot find symbol
public abstract class BaseRedirectorHelperTask extends Task {
/root/sam/tomcat-10.0.14/java/org/apache/catalina/ant/AbstractCatalinaCommandTask.java:64: error: cannot find symbol
public StringBuilder createQueryString(String command) throws BuildException {
^
Thanks,
Marco

HOw to run Jmeter tests with Maven?

Can someone suggest how to run Jmeter tests with Maven please? This is just a simple jmeter script with http call to google.com with no variables. Just want to start with a simple one.
I've created the path C:\Jmeterautomation\src\test\jmeter\google.jmx that maven recognizes
I've created pom.xml in this directory C:\Jmeterautomation
This is what pom looks like
<?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>
<groupId>com.adp.ds.services</groupId>
<artifactId>01-run-with-Maven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-Maven-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
when I open command window, and go to this C:\Jmeterautomation and type mvn verify, I'm getting error mvn is not recognized as internal or external command
I've download this jmeter-maven-plugin-1.4.1.jar and kept in C:\Jmeter\apache-jmeter-2.13\lib\ext.
what am I doing wrong here?Tried all possible ways that I know off,Is there any step by step instructions that can go through the process, please suggest.
Thanks in advance
I'm getting error mvn is not recognized as internal or external command
Please install maven first:
https://maven.apache.org/guides/getting-started/windows-prerequisites.html

Maven assembly plugin - dependendy on module of type ear in multi module project

My question is whether there is anyway with the maven assembly plugin to reference a dependency of type ear that is not installed in the artefactory/repository.
Consider the multi-module project below with parent:
<?xml version="1.0" encoding="UTF-8"?>
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>parent</name>
<modules>
<module>module1</module>
<module>assembly</module>
</modules>
</project>
with ear module:
<?xml version="1.0"?>
<project ...>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.test</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<groupId>com.test</groupId>
<artifactId>module1</artifactId>
<packaging>ear</packaging>
<name>EAR Module</name>
</project>
and assembly module:
<?xml version="1.0"?>
<project ...>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.test</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<groupId>com.test</groupId>
<artifactId>assembly</artifactId>
<packaging>jar</packaging>
<name>Assembly Module</name>
<dependencies>
<!-- Note - the dependencies (and their associated dependencies etc) are
subsequently available for assembly dependencySet includes -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module1</artifactId>
<type>ear</type>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
with an assembly xml :
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bundle</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!--
Include EAR
-->
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputFileNameMapping>xxxxxxxxx.ear</outputFileNameMapping>
<outputDirectory>eardirectory</outputDirectory>
<includes>
<include>${pom.groupId}:module1:ear</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
From a brand new checkout with empty repository, the parent project pom fails when doing a mvn compile with the error
[ERROR] Failed to execute goal on project assembly: Could not resolve dependencies for project com.test:assembly:jar:1.0: Could not find artifact com.test:module1:ear:1.0 ...
Whereas, if I first go to the ear module and do a mvn install, then subsequent mvn compile from the parent module works perfectly.
Additionally, if the ear module was instead the standard jar module, then this issue does not exist. Such that, if the dependency module had been of type jar, there is no need to first install it in to the local repos before doing the initial mvn compile from the parent.
Switching the dependency in the assembly pom to be of scope 'runtime' allows an initial mvn compile to succeed, however a mvn test would fail. Setting the dependency as optional also did not succeed.
Can anyone suggest a potential solution?
I'm hoping I don't need to go down the fileSet path, or utilize the maven-dependency-plugin. This dependency only exists in the pom so that the assembly plugin can package it / reference it. It is not for compilation / runtime / testing. So none of the maven dependency scopes make any sense.

Maven not passing overriden properties to ant

Currently running into a weird problem with a Maven build that is making a call to ant, within the parent pom the following property is defined: -
<jboss.home>${env.JBOSS_HOME}</jboss.home>
I am trying to override this by passing in -Djboss.home when I run Maven.
This build contains a profile that when activate calls an Ant build: -
<ant antfile="build.xml" inheritRefs="true">
<target name="all"/>
</ant>
The Ant script uses the property: -
<property name="jboss.dir" value="${jboss.home}"/>
An subsequently outputs it: -
<echo message="jboss dir is: ${jboss.dir}"/>
The problem is that the value it output is ${env.JBOSS_HOME}
Other properties in the parent pom I can override from the command line.
Even the jboss.home property does appear to be overridden if use elsewhere within the Maven build.
After trying various combinations of command it almost appears that the set of properties passed to Ant are resolved from the poms BEFORE any overrides from the command line. If I set the JBOSS_HOME environment variable then all places this variable is used have the correct values.
Is there something I am missing to be able to override this variable on the command line and have the overridden value used in the Ant script?
Stumbled into this problem today, and did discover an answer. This link provides some background: http://technotes.khitrenovich.com/properties-resolution-maven-implications-antrun-plugin/
Maven properties will work just fine if the property is referenced inline within the <target>. e.g:
<execution>
..
<configuration>
<target>
<echo message="Command-line override of external.property will work OK like this: ${external.property}"/>
</target>
</configuration>
</execution>
However, if you use an external ant file written like this, many/most properties will work, BUT command-line overrides will not be passed into the ant file. You will get the non-overridden value instead.
<execution>
..
<configuration>
<target>
<property name="external.property" value="${external.property}" />
<ant antfile="build.xml" target="all" />
</target>
</configuration>
</execution>
Instead, for external ant files, use this syntax. The command line value will be passed through correctly to the external antfile:
<execution>
..
<configuration>
<target>
<ant antfile="build.xml" target="all" >
<property name="external.property" value="${external.property}" />
<ant/>
</target>
</configuration>
</execution>
The problem is that ${env.JBOSS_HOME} is a system environment variable and you are instead passing to the JVM a system property -Djboss.home=.... These are two different things. Apart from that, any variables, args and so on in the Java world are case sensitive.
You seem do be doing all the right things, it works for me, I have made a working example with 2 pom.xml files. The parent pom looks like this:
<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.stackoverflow.test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<name>Test</name>
<packaging>pom</packaging>
<modules>
<module>test-ant-properties</module>
</modules>
<properties>
<jboss.home>${env.JBOSS_HOME}</jboss.home>
</properties>
</project>
Then I created a module pom.xml in the sub-folder test-ant-properties that looks like this:
<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>com.stackoverflow.test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
</parent>
<artifactId>test-ant-properties</artifactId>
<name>Test maven ant properties</name>
<profiles>
<profile>
<id>jboss</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>jboss-ant</id>
<phase>install</phase>
<configuration>
<target>
<property name="jboss.dir" value="${jboss.home}"/>
<echo message="jboss dir is: ${jboss.dir}"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
I don't have JBOSS installed so for testing purpose I set the environement variable to test1234 like this:
set JBOSS_HOME=test1234
When I execute the parent pom with the jboss profile
mvn install -Pjboss
I get the following result: [echo] jboss dir is: test1234
When I execute the same command with the jboss.home setting
mvn install -Pjboss -Djboss.home=my_custom_variable
I get the following result: [echo] jboss dir is: my_custom_variable

Resources