bring -f option to multi module - maven

there is -f option in maven, that allows to specify alternate pom.xml file. Is there a possibility, that I can also bring this behaviour to the executed modules? Now it looks like, that when I have this structure: projectA: pom.xml pom.xml2
projectB: pom.xml pom.xml2
And when I run maven with -f pom.xml2 option as reactor with projectB specified as module, it looks like that it picks pom.xml2 from the projectA, and it picks pom.xml from projectB. Is there a way, how can I propagate the -f option to the modules?
Thanks for answering.

Because we can specified pom file in module definition.1
Here's an example for using alternative pom file in module.
<modules>
<module>child1/pom-jdk14.xml</module>
<module>child2/pom-jdk14.xml</module>
</modules>

As Jörn Horstmann comments I would try lots of things to get this working with profiles in one pom.
If that's not possible the only way I can think of to get this working is to bypass the normal maven mechanism by using a "switching pom" with profiles. This pom is put as pom.xml in each module and has a profile for each of your pom.xml2 (or others) and in that profile executes another maven build f.e. via the antrun-plugin with the -f for the pom you need:
<profile>
<id>xml2</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>build pom.xml2</id>
<phase>prepare-package</phase> <!-- whatever suits you -->
<configuration>
<target>
<echo level="info" message="Building pom.xml2..." />
<exec executable="cmd" dir=".">
<arg value="/c" />
<arg value="mvn" />
<arg value="-f" />
<arg value="pom.xml2" />
<arg value="install" /> <!-- enter which phase you need -->
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Related

Detekt plugin not able to download from Maven central

I am working with Kotlin and want to do static analysis using Detekt plugin. My problem is, when I want to download it from Maven central repository, it is giving me below error. But when I use company's repository (Nexus), it does not give me any error and downloads it smoothly. I don't understand this.
Can someone tell me why this is happening? I want to use this plugin and have not found out any other alternative.
Below is my error :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (detekt) on project agathe: Execution detekt of goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run failed: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.8 or one of its dependencies could not be resolved: Could not find artifact com.beust:jcommander:jar:1.74 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
Kindly find my POM file below.
<properties>
..
<sonar.kotlin.detekt.reportPaths>${project.build.directory}/detekt.xml</sonar.kotlin.detekt.reportPaths>
..
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<!-- This can be run separately with mvn antrun:run#detekt -->
<id>detekt</id>
<phase>verify</phase>
<configuration>
<target name="detekt">
<java taskname="detekt" dir="${basedir}"
fork="true"
failonerror="false"
classname="io.gitlab.arturbosch.detekt.cli.Main"
classpathref="maven.plugin.classpath">
<arg value="--input"/>
<arg value="${basedir}/src"/>
<arg value="--filters"/>
<arg value=".*/target/.*,.*/resources/.*"/>
<arg value="--report"/>
<arg value="xml:${project.build.directory}/detekt.xml"/>
</java>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.gitlab.arturbosch.detekt</groupId>
<artifactId>detekt-cli</artifactId>
<version>1.0.0-RC14</version>
</dependency>
</dependencies>
</plugin>

How to set ANTLR3 extended option -Xmaxinlinedfastates in maven configuration?

Is it possible to set the max DFA states before table used rather than inlining in the configuration of the plugin maven antlr3 like the extended option -Xmaxinlinedfastates in the command line of antlr.Tool ?
I find it for ant script but nothing with maven.
If yes, how to ?
Thanks.
Thanks to Jiri Tousek.
I found an alternative to what I call a gap in the maven antlr3 plugin. Using the maven antrun plugin allowed me to solve this problem.
Here is the statement I made in pom.xml and that works for me:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<target>
<!-- Place any Ant task here. You can add anything you can add between
<target> and </target> in a build.xml. -->
<java classname="org.antlr.Tool" fork="true"
failonerror="true">
<arg value="-verbose" />
<arg value="-Xmaxinlinedfastates"/>
<arg value="10"/> <!-- Value for the exended option -Xmaxinlinedfastates -->
<arg path="./src/main/antlr3/*.g" />
</java>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

How to setup multiple fitnesse suites in pom file using maven-antrun-plugin ? and how to call the specific suite run among the configured suits?

I am able to run the FitNesse suite from maven build with the following setup.
<properties>
<fitnesse.version>20160618</fitnesse.version>
</properties>
<dependencies>
<dependency>
<groupId>org.fitnesse</groupId>
<artifactId>fitnesse</artifactId>
<version>${fitnesse.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.fitnesse.plugins</groupId>
<artifactId>maven-classpath-plugin</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>start-fitnesse-integration</id>
<phase>integration-test</phase>
<configuration>
<tasks>
<echo taskname="fitnesse" message="Starting FitNesse..." />
<java classname="fitnesseMain.FitNesseMain" classpathref="maven.runtime.classpath"
fork="true" failonerror="true">
<jvmarg value="-Xmx1024m" />
<arg line="-p 9000" />
<arg line="-c FrontPage.TestSuite?suite&amp;format=text" />
<arg line="-e 0" />
<!-- <arg line="-d ." /> -->
</java>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am running the FitNesse suite using the below command.
mvn clean install
Now I want to configure execution of multiple FitNesse suites as part of pom.xml and want to run specific suite as part of maven build.
How can I achieve this?
There are a couple of ways to configure multiple suites to be run:
Add multiple execution elements to your pom (inside the executions element you already have) one per suite, each with a unique id
Place all suites you want to run under a shared parent suite (and run the parent suite). You can also use symbolic links to achieve this.
Create a suite query page to indicate which suites should be run (and run that page).
Create a suite cross reference page and run that
Give all suites the same tag and use filters to select all suites to run based on the tag
P.S. Why are you using the antrun plugin instead of maven-exec?

Using XJB with jaxb2-maven-plugin

I have a multi-module maven project in the following structure:
root-module
|__module-a
| |__src
| |__main
| |__xsd
| | |__my.xsd
| |__xjb
| |__my.xjb
|__module-b
The POM for root module simply aggregates module a and b (among other things):
<project>
<artifactId>root-module</artifactId>
<packaging>pom</packaging>
<modules>
<module>module-a</module>
<module>module-b</module>
</modules>
</project>
And the POM for module a is as follows (among other things):
<project>
<parent>
<artifactId>root-module</artifactId>
</parent>
<artifactId>module-a</artifactId>
<properties>
<my-definitions.xsd>${basedir}/src/main/xsd/my.xsd</my-definitions.xsd>
<my-bindings.xjb>${basedir}/src/main/xjb/my.xjb</my-bindings.xjb>
<my.output>${basedir}/target/generated-sources/jaxb/my</my.output>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-my-classes</id>
<phase>generate-sources</phase>
<goals><goal>xjc</goal></goals>
<configuration>
<sources><source>${my-definitions.xsd}</source></sources>
<xjbSources><xjbSource>${my-bindings.xjb}</xjbSource></xjbSources>
<outputDirectory>${my.output}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
So when I run mvn at module-a, everything works fine and the build succeeds. But when I run it at root-module, I get an exception from the XJC plugin where it tries to find the bindings file under the root-module:
com.sun.istack.SAXParseException2; IOException thrown when processing "file:/home/root-module/src/main/xjb/my.xjb". Exception: java.io.FileNotFoundException: /home/root-module/src/main/xjb/my.xjb (The system cannot find the path specified).
What is interesting is, it is able to locate the XSD correctly:
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.1:xjc (generate-my-classe) on project module-a:
[ERROR] +=================== [XJC Error]
[ERROR] |
[ERROR] | 0: file:/home/root-module/module-a/src/main/xsd/my.xsd
[ERROR] |
[ERROR] +=================== [End XJC Error]
Any clues?
Is this a configuration issue in the build script?
Specifics of my build system:
Using Maven 3.2.5
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.1</version>
Referring JAXB2 Maven plugin documentation from here.
Also searched few related questions on SO, but they do not explain my specific problem anywhere.
UPDATE: Looks like an open issue. Keeping the thread open in case there is a workaround.
Updating to version 2.2 of the plugin appears to work.
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
I had the same problem when using version 2.1 of the plugin. Simply changing to version 2.2 fixed the issue.
Until a plugin resolution is available, I am using the following ant-run hack:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-my-classes</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir dir="${project.build.directory}/generated-sources/jaxb/my" />
<exec executable="${env.JAVA_HOME}/bin/xjc.exe" dir="${project.basedir}/src/main/xsd">
<arg value="-p" />
<arg value="my.package" />
<arg value="-b" />
<arg value="${project.basedir}/src/main/xjb" />
<arg value="-d" />
<arg value="${project.build.directory}/generated-sources/jaxb" />
<arg value="." />
</exec>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
UPDATES:
Discussion on Github.
Considering Apache CXF Utils as an alternative.

Is there a maven plugin to install the project?

I'm new with Maven, I just finished to read the Sonatype guide and I'm very satisfied by the functions that maven makes available. I created an application distribution (.zip) package and I would like to know if there is a manner to use maven as an installer.
I don't mean the installation that maven does into the local repository, what I mean is explained by the following example:
I've a folder with a jar file, an .sql script, a /lib and obviously a pom.xml file.
I would like that maven installs this project for me when I execute the "mvn" command.
So maven should:
- Copy the jar file in the ${TOMCAT_HOME}\webapps directory.
- Execute the sql script on the postgresql database
- Copy the \lib directory in c:\myLibs
- etc etc
During this process it should also make some checks (example TOMCAT_HOME is set on the system? Postgres is turned on? etc.) and ask to the user some parameter (example "The installation will reset the database do you want to continue?" or "Please insert the database password: ".
Is there a maven plugin that helps to do this? If not is there an application alike maven specialized to create "installer" ? Is it a standard, widespread application?
Thanks a lot for your help!
Try:
mvn deploy.
Add to your pom
<distributionManagement>
<repository>
<id>sonatype.internal</id>
<name>Internal Release Repository</name>
<url>http://sonatypeAddress:sonatypePort/context</url>
</repository>
</distributionManagement>
Plugins section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<configuration>
<tag>${build.tag}</tag>
<username>${scm.username}</username>
<password>${scm.password}</password>
</configuration>
</plugin>
antrun plugin - and make what you want.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<dependencies>
...
</dependencies>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<configuration>
<target>
<delete dir="mylocalization" />
<copy file="target/out/my.jar" tofile="mylocalication" />
<copy todir="mylocalization/doc">
<fileset dir="target/doc" />
</copy>
<copy todir="mylocalization/somethingMore">
<fileset dir="target/more">
<include name="a.txt" />
<include name="b*.txt" />
</fileset>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
See also maven-wagon

Resources