replacer Maven issue with lifecycle phases - java

Can't compile the following pom.xml plugin:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<extensions>true</extensions>
<executions>
<execution>
<goals><goal>replace</goal></goals>
<phase>process-sources</phase>
</execution>
</executions>
<configuration>
<ignoreMissingFile>false</ignoreMissingFile>
<file>target/generated-sources/r/com/actionbarsherlock/R.java</file>
<outputFile>target/generated-sources/r/com/actionbarsherlock/R.java</outputFile>
<regex>false</regex>
<token>static final int</token>
<value>static int</value>
</configuration>
</plugin>
Receive the following error:
Description Resource Path Location Type
Plugin execution not covered by lifecycle configuration: com.google.code.maven-replacer-plugin:replacer:1.5.3:replace (execution: default, phase: process-sources) pom.xml /ActionBarSherlock line 67 Maven Project Build Lifecycle Mapping Problem
We tried different plugins, but we can never get to make it work in the "process-sources" phase. Looks like this phase has something special or needs to be configured somehow?
Add some details by request:
IDE: ADT v22
Maven version: 3.0.4
The error is signaled on the POM.xml next to the 'executions' line. If I change the process-sources phase to prepare-package, the error disappears. Unfortunately at that point the replacement is useless.

Related

Skip running PITest in maven build

I'm trying to run a maven build from command line and exclude PITest from running any mutations. Currently the reports are failing and we need to be able to give a parameter to ignore running the mutation tests or ignore the results and continue the build
I've running with some parameters like mvn package -Dpit.report=true
or mvn package -Dmaven.report.skip=true
This is the PITest setup in my pom
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.1.10</version>
<configuration>
<timestampedReports>false</timestampedReports>
<mutationThreshold>95</mutationThreshold>
</configuration>
<executions>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>mutationCoverage</goal>
</goals>
</execution>
</executions>
</plugin>
The problem is that is is still running PITest and causing the build to fail
There is no native way of skipping a plugin execution, but there are least 2 workarounds:
First, is adding a property to override execution phase:
Define a property pitPhase with default value as the default phase of plugin execution.
Then in plugin configuration:
<execution>
<phase>${pitPhase}</phase>
...
</execution>
After that, when you want to skip execution mvn -DskipPit=pitPhase package
The other alternative is to add a Maven profile with the plugin execution
The execution of Pitests can be skipped in Maven.
In your pom.xml:
Set in general properties:
<properties>
<pitest.execution.skip>true</pitest.execution.skip>
</properties>
Set in the plugin:
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>Your_Version</version>
<configuration>
<skip>${pitest.execution.skip}</skip>
</configuration>
</plugin>
Since 1.4.11 there is the option skipPitest. See here: https://github.com/hcoles/pitest/releases/tag/pitest-parent-1.4.11
So you do: -DskipPitest

GWT compilation error with Maven: No instance of Presenter is defined. Forget to annotate #Presenter or #EventHandler?

Migrate from Ant Ivy to Maven build tool.
Little info about project:
Multi-module project with few deploying artifacts.
On Ant Ivy everything fine, compilation and deploy passes normal.
Migrate on Maven pass successfully with 2.7.0 GWT version. After increasing version to 2.8.1, stared to get gwt compilation error.
[ERROR]com.example.gwt.client.module.user.GWTEventBus:
Method createInfoPage: No instance of com.example.gwt.client.module.user.presenter.
info.InfoPresenter is defined. Have you forgotten to annotate your event handler
with #Presenter or #EventHandler?
[INFO] at com.mvp4g.util.config.loader.annotation.EventsAnnotationsLoader.
buildPresentersAndEventHandlers (EventsAnnotationsLoader.java:425)
...long stack trace ...
at com.google.gwt.dev.Compiler.main(Compiler.java:125)
[INFO][ERROR] Errors in 'com.example.gwt.GWTModule'
[INFO][ERROR] Line 137: Failed to resolve 'com.mvp4g.client.Mvp4gModule' via deferred binding
Line 137 contain Mvp4gModule module = GWT.create(Mvp4gModule.class);
Attempts to fix:
1. Compared classpath mapped dependencies from Ant Ivy with Maven classpath, everything the same. All versions of dependencies and plugins are fine, without any conflicts.
2. Tried with two different gwt maven plugins, but get the same error with any configurations:
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.0-rc-6</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>import-sources</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<moduleName>com.example.gwt.GWTModule</moduleName>
<jvmArgs>
<jvmArg>-Xmx768M</jvmArg>
<jvmArg>-Xss10M</jvmArg>
</jvmArgs>
<failOnError>false</failOnError>
<sourceLevel>1.8</sourceLevel>
<compilerArgs>
<arg>-compileReport</arg>
<arg>-XcompilerMetrics</arg>
</compilerArgs>
<warDir>${project.build.directory}/${project.build.finalName}</warDir>
<classpathScope>compile+runtime</classpathScope>
<startupUrls>
<startupUrl>Validation.html</startupUrl>
</startupUrls>
</configuration>
</plugin>
Main strangeness is that Ant compile successfully. Ant's compile-gwt target has the same configuration and arguments as Maven's gwt-plugin.

How to run a Maven enforcer rule before the Maven release prepare changes the pom.xml?

I've created a custom Maven enforcer rule. This rule will check the content of the <scm><connection> value to ensure that it points to the trunk or branches/* (i.e. not a tag).
This enforcer is configured in the pom.xml like that:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<dependencies>
<dependency>
<groupId>my.company</groupId>
<artifactId>maven-release-enforcer</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>enforce-release-check</id>
<goals>
<goal>enforce</goal>
</goals>
<phase>validate</phase>
<configuration>
<rules>
<releaseCheck implementation="my.company.maven.release.enforcer.MavenReleaseEnforcer"/>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Unfortunately, when we use it with the Maven Release plugin, the latter plugin changes the content of the <scm><connection> value during its [enter link description here]prepare2 goal, so before the enforcer is effectively called. This results in a failure of my custom rule, as the <scm><connection> points to a tag at this time.
So my question: is there a way to force the enforcer to be called before the Maven Release plugin start to modify the pom.xml?
ps: the Jenkins job is divided into 2 steps: mvn clean release:prepare and mvn release:perform.
when you call
mvn clean release:prepare
only the clean phase and the prepare goal is excuted.
You could use
mvn clean validate release:prepare
to include the validate phase or
mvn clean maven-enforcer-plugin:enforce release:prepare
to just trigger the enforcer plugin

Mechanics of Goal execution in Maven

I have the wsimport plugin in my project.
I would like to execute the wsimport. According to the website, the string to execute is "mvn jaxws:wsimport".
Firstly, is this string deductable from the XML ?
The artifact ID is :
<artifactId>jaxws-maven-plugin</artifactId>
and goal :
<goal>wsimport</goal>
so is the artifact-part just the substring of the artifactid leading up to "-maven-plugin" ?
..And when I execute my plugin goal "mvn jaxws:wsimport" does this completely ignore which phase I am in? Ie. is this running outside of the phase? And if no, is there a way to run this standalone?
ie. is there a way I can set the phase to none? (eg [phase]none[/phase]).
Pom code :
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>wsimport-from-jdk</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<executable>${tool.wsimport}</executable>
<wsdlUrls>
<wsdlUrl>http://WorkPC:8080/server-web/AirlineWS?wsdl</wsdlUrl>
</wsdlUrls>
<packageName>com.bluewalrus</packageName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
When you issue a command like mvn [plugin]:[goal], it launches Maven out of any lifecycle, so if you do not intend to perform that goal inside a lifecycle, but only via such commands, you shouldn't have any <execution> defined, just place <configuration> right after <version>.
About how Maven can shorten the plugin call (i.e. mvn dependency:tree instead of mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:tree), it is based on several conventions:
When no version defined, it tries to take the latest from available repositories
When the groupId is omitted, it looks among the predefined or user-defined pluginGroups to find a suitable one. See here for more information (Configuring Maven to Search for Plugins)
On the same page, you can see how plugins prefixes are used to shorten the plugin prefix, by using a prefix instead of the artifactId of the plugin. Thirdparty plugins should use [prefix]-maven-plugin construction, and it looks OK here.
And to disable the default execution of a plugin (although it might not be useful in this case), you can use this answer

Using property file in maven

I don't quite understand how it can be used. There is a property defined in the file. I try to use maven property plugin to read it and save. The property is used in the liquibase plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/main/resources/properties/app.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>2.0.5</version>
<configuration>
<propertyFile>src/main/resources/db/config/${env}-data-access.properties</propertyFile>
<changeLogFile>src/main/resources/db/changelog/db.changelog-master.xml</changeLogFile>
<migrationSqlOutputFile>src/main/resources/db/gen/migrate.sql</migrationSqlOutputFile>
<!--<logging>debug</logging>-->
<logging>info</logging>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<!--<verbose>false</verbose>-->
<dropFirst>true</dropFirst>
</configuration>
</plugin>
According to the documentation in order to read property and save it I have to run: mvn properties:read-project-properties. But I'm getting the following error in this case:
[ERROR] Failed to execute goal org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:read-project-properties (default-cli) on project SpringWebFlow:
The parameters 'files' for goal org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:read-project-properties are missing or invalid -> [Help 1]
I've changed pom.xml, removed the <execution> section and moved the <configuration> section:
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<configuration>
<files>
<file>src/main/resources/properties/app.properties</file>
</files>
</configuration>
Ok. now, when I run mvn properties:read-project-properties the error disappeared. But where in this case the property is saved? Cause when I start the following maven goal:
mvn liquibase:update
I can see that the ${env} property is not defined. Liquibase tries to use the src/main/resources/db/config/${env}-data-access.properties file.
What am I doing wrong? How to read a property from the file, so it could be accessible from different maven plugins?
The problem is that "mvn liquibase:update" is a special plugin goal and is not part of the maven life cycle. So it never passes the initialize phase and so the property plugin is not executed.
The following will work
mvn initialize liquibase:update
One solution would be to call liquibase:update in one of the maven lifecylce phases like compile, package ..., but then it would be executed on every build.
Or you use the maven-exec plugin to call "initialize liquibase:update" from maven. Or you create a profile were you bind the liquibase:update to the lifecylce phase initialize and the udate is executed when you call
mvn initialize -Pliquibase
I do not know a better solution to this problem and I could not find a suitable solution for this.
For reference:
Maven lifecycle

Categories

Resources