Maven: mavent--ant-run does not support attribute - maven-3

Currently I'm working on a maven build script and my next issue is to copy source files into a target folder. I found this thread and it works fine unless I don't use the 'flattern' attribute. I know that the computer makes all things right, but I wonder why the build will fail.
Here my code using the maven antrun plugin:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<target>
<copy todir="${project.basedir}/target" flattern="true" overwrite="true">
<fileset dir="${project.basedir}/src/main"/>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The error message I get is
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project setup_core: An Ant BuildException has occured: copy doesn't support the "flattern" attribute
[ERROR] around Ant part ...<copy todir="C:\Projekte\CQ5_Migration\setup\core_upload/target" overwrite="true" flattern="true">... # 4:101 in C:\Projekte\CQ5_Migration\setup\core_upload\target\antrun\build-main.xml: The <copy> type doesn't support the "flattern" attribute.
[ERROR] -> [Help 1]
Have I overseen somthing and if so what is/are the missing fact(s)?
Thanks again for your help :-)

It should be "flatten" not "flattern".
Remove the 'r'.

Related

Maven antrun plugin missing target task after combining from multiple profiles

This is quite an interesting problem I have 2 profiles as defined below. I'm using Maven 3.6.3 with the latest Java 11.
<profiles>
<profile>
<id>assembly-unzip</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<unzip src="src1.zip" dest="dest10" />
<copy file="copy1.txt" todir="dest11"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>assembly-get</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<mkdir dir="download" />
<get src="src20" dest="dest"/>
<unzip src="dest/src20}" dest="dest"/>
<get src="src21" dest="dest"/>
<unzip src="dest/src21}" dest="dest"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
When I activate BOTH profiles, I get from (-X) that Maven combines the 2 antrun plugin configurations into a single configuration that looks like this:
<configuration>
<exportAntProperties default-value="false"/>
<failOnError default-value="true"/>
<localRepository>${localRepository}</localRepository>
<mavenProject default-value="${project}"/>
<pluginArtifacts>${plugin.artifacts}</pluginArtifacts>
<session default-value="${session}"/>
<skip default-value="false">${maven.antrun.skip}</skip>
<sourceRoot>${sourceRoot}</sourceRoot>
<target>
<mkdir dir="download"/>
<get src="src20" dest="dest"/>
<unzip src="dest/src20}" dest="dest"/>
<get src="src21" dest="dest"/>
<unzip src="dest/src21}" dest="dest"/>
<copy file="copy1.txt" todir="dest11"/>
</target>
<testSourceRoot>${testSourceRoot}</testSourceRoot>
<versionsPropertyName default-value="maven.project.dependencies.versions"/>
</configuration>
What's missing from the combined configuration is:
<unzip src="src1.zip" dest="dest10" />
I've tried this multiple times in different ways and the long and short of it is that it seems like if the from the 1st profile that Maven processes has an task (for example) then any tasks in the of the 2nd profile will be ignored and NOT part of the combined configuration. Please be aware that i'm just using as an example. I've tried it with other tasks and see the same behavior.
Any thoughts?
You can do two things:
Use an <id> to each of your execution: without it, you get the default, and that's what maven use to determine duplicate configuration items when it merge them.
Use combine.children and so on. I would advise you not to do that, but you may read more on blog.sonatype.com or at maven.apache.org.
You could also directly use the power of ant, create target and invoke it conditionally using condition.

Rinsim, compile executable file failed, with maven dependency

I try to get a executable file for my code using this maven plug from How can I create an executable JAR with dependencies using Maven?. However it ends up with the error Failed to execute goal com.mycila:license-maven-plugin:3.0:check (check-license) on project rinsim-example: Execution check-license of goal com.mycila:license-maven-plugin:3.0:check failed: Cannot read header document LICENSE_HEADER. Cause: Resource LICENSE_HEADER not found in file system, classpath or URL: no protocol: LICENSE_HEADER -> [Help 1]>
this is the part of my maven file:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.github.rinde.rinsim.examples.project.DDRP</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Thank you.
It seems like you've copied part of the RinSim pom.xml, including the license-maven-plugin? You should probably remove the license-maven-plugin plugin execution, as that is the source of this error message. This is the definition of the license-maven-plugin in RinSim:
<pluginExecution>
<pluginExecutionFilter>
<groupId>com.mycila</groupId>
<artifactId>
license-maven-plugin
</artifactId>
<versionRange>
[2.11,)
</versionRange>
<goals>
<goal>check</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
Alternatively, you can choose to use the license-maven-plugin. This plugin allows you to set a license header on every source file.

How to have a pom.xml but prevent Maven being used for building?

I have a project for which I have created a pom.xml. However, I'm not using Maven as my build system, I am using something else (e.g. ANT). But I want the pom.xml to exist for the use of other tools, e.g. IDEs. How can I make sure, that if someone downloads my project and tries to build it with Maven, they will get a clear indication that they are doing the wrong thing?
Add the following to pom.xml:
<properties>
<maven.build.not.supported>
Do not use Maven to build this module. Please see README.html for
instructions on how to build it.
</maven.build.not.supported>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>fail-clean-lifecycle</id>
<phase>pre-clean</phase>
<configuration>
<tasks>
<fail message="${maven.build.not.supported}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>fail-default-lifecycle</id>
<phase>validate</phase>
<configuration>
<tasks>
<fail message="${maven.build.not.supported}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>fail-site-lifecycle</id>
<phase>pre-site</phase>
<configuration>
<tasks>
<fail message="${maven.build.not.supported}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Since we cannot apparently bind a plugin execution to multiple phases, we need to repeat the execution block three times, one for each of the built-in lifecycles (clean, default and site). To avoid duplication of the failure message, we store it in a Maven property and reuse that property in each execution. In each execution we bind to the first phase of the lifecycle to fail it immediately.

Maven: Overview for the values of Maven properties

I would like to find out the values of all Maven properties as they apply to some Maven project.
mvn help:system lists OS environment variables and JVM system properties, but no Maven properties.
mvn help:evaluate only works in an interactive mode, that means I have to type a single Maven property, (e.g. ${project.build.outputDirectory}) to get the value of that property.
I'm looking for a way get a full list of all Maven properties and their values.
As a workaround, add this to the <plugins> ... </plugins> section inside your project's pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Now execute mvn validate.
On the console, prefixed with [echoproperties], there will be the full list of system properties, including those set by Maven such as project.build.outputDirectory, basedir, and settings.localRepository.
the maven-help-plugin does what you want, just call it with -Dexpression=project.properties this will print the properties tag of the effective pom.
mvn help:evaluate -Dexpression=project.properties
Bonus Points when you just want the properties output and not the maven output
mvn help:evaluate -Dexpression=project.properties -q -DforceStdout
or with the explicit version because -DforceStdout works since version 3.1.0
mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.properties -q -DforceStdout
Not sure if helps, but I found this when trying to do the same thing:
mvn com.github.ekryd.echo-maven-plugin:echo-maven-plugin:echo -Decho.message='${project.build.testOutputDirectory}'
From here.
Adding the following to ${user.home}/.m2/settings.xml:
<pluginGroups>
<pluginGroup>com.github.ekryd.echo-maven-plugin</pluginGroup>
</pluginGroups>
the command can be shortened to:
mvn echo:echo -Decho.message='${project.build.testOutputDirectory}'
I don't know how to get them "officially", but here is a workaround. Add maven-antrun-plugin to your project and run mvn test -X. The plugin will show all properties passed to it from Maven. The list looks complete to me.
Actually project.build.outputDirectory is there but you need to execute in 'compile' phase, and NOT in 'validate'. I guess what properties are available also depends on the current phase for the executing goal of a particular plug-in, in this case 'maven-antrun-plugin'.
<!-- Ant Run Plugin for debugging pom.xml and calling ant tasks -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${ant.plugin.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Had the same issue. Changed the timeout and maxheap in findbugs configuration through maven.
The below fixed it for me :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<maxHeap>2048</maxHeap>
<timeout>1800000</timeout>
</configuration>
</plugin>

How to run an ant target from Maven2?

How do i run a specific target with the antrun-plugin from the command line?
mvn antrun:run doesn't make it run.
<project>
...
<build>
<plugins>
...
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>myExecution</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<ant target="myTarget" inheritRefs="true">
...
</ant>
</tasks>
</configuration>
</execution>
</executions>
<dependencies>
...
</dependencies>
</plugin>
...
</plugins>
...
</build>
...
</project>
How do i run a specific target with the antrun-plugin from the command line?
To strictly answer this question, you can't, and you don't.
What you can do is either:
1. provide a plugin-level configuration
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
....
</configuration>
</plugin>
And this configuration will be used when invoking the plugin (regardless of how the plugin is invoked: from the cli, a part of the lifecycle).
2. provide an execution-level configuration (which is what you did)
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>myExecution</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<ant target="myTarget" inheritRefs="true">
...
</ant>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
And then invoke the phase to which the plugin is bound (deploy in this case).
3. provide an execution-level configuration for the special default-cli execution Id
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<tasks>
<ant target="myTarget" inheritRefs="true">
...
</ant>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
As of Maven 2.2.0 (see MNG-3401), goals invoked directly from the command line can be configured in the POM separately from other plugin invocations using a special executionId called default-cli. In other words, the above configuration would be only used when invoking the plugin from the command line.
But in any case, you can't invoke a specific Ant target inside a configuration element. You could maybe mess with profiles to implement something approaching but, if you really want to go this direction, my advice would be to use Ant.
References
Guide to Configuring Default Mojo Executions
You can, by being sneaky.
In pom.xml:
...
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<configuration>
<target>
<ant target="trampoline" />
</target>
</configuration>
</plugin>
...
In build.xml:
...
<target name="trampoline">
<echo message="Executing target '${mvnAntTarget}'"/>
<antcall target="${mvnAntTarget}" />
</target>
<target name="testTarget">
<echo message="Yay, I'm a test target.."/>
</target>
....
And then, by running:
$ mvn antrun:run -DmvnAntTarget=testTarget
The Ant's testTarget will be run.
Refer to the example at : http://docs.codehaus.org/display/MAVENUSER/Antrun+Plugin
Basically write your ant targets in a regular build.xml.
Then define a single <target> under configuration where you dynamically decide what is the buildFile name and targetName and do a
<ant andfile="${buildFile}" target="${targetName}" inheritAll="true" inheritRefs="true"/>
I'm not too sure that's the reason it doesn't work but the syntax you're using is deprecated. You should have something like:
<configuration>
<target name="myTarget">
<!--
Place any Ant task here. You can add anything
you can add between <target> and </target> in a
build.xml.
-->
</target>
<configuration>
More details here:
http://maven.apache.org/plugins/maven-antrun-plugin/usage.html

Resources