I'm using grails 2.4.4.
Some of my classes are annotated and a APT (annotation processing tool) has to process these annotations during compilation to generate some sources.
I was able to get everything done with the workaround of creating a maven pom.xml by running grails generate-pom and from there add specific plugins and configure them.
Is there a possibility to use the built-in grails compiler config BuildConfig.groovy to reach the same goal without the detour via maven pom.xml?
To be more specific, I'm creating a workflow with AWS SWF. And SWF uses annotations that should generate some client classes. Therefor in the pom.xml I added this. It works perfectly when I run mvn compile:
<build>
...
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>src/generated</outputDirectory>
<processor>com.amazonaws.eclipse.simpleworkflow.asynchrony.annotationprocessor.AsynchronyDeciderAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-flow-build-tools</artifactId>
<version>1.9.34</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.21</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
</dependencies>
</plugin>
...
</build>
I found out my self how to to it within grails.
Basically I created a script that you can call with the grails command. This script is nothing else but a gant script with which you can interfere with ant. Plus I had to add libraries to the libs folder in grails in order to have them in the classpath.
These are the steps:
Create a new grails script
grails create-script generateSources This will create a script called GenerateSources.groovy into your grails scripts directory
Edit the GenerateSources.groovy file
includeTargets << grailsScript("_GrailsCompile")
target(generateSources: "Generates sources for SWF workflow") {
ant.delete(dir:"src/generated/java")
ant.delete(dir:"target/generated-classes")
depends(compile)
ant.mkdir(dir:"src/generated/java")
ant.mkdir(dir:"target/generated-classes")
ant.javac(destdir:"target/generated-classes", classpathref:"grails.compile.classpath", source:"1.7", target:"1.7"){
compilerarg(value:"-proc:only")
compilerarg(value:"-s")
compilerarg(value:"src/generated/java")
src(path:"src/java")
}
}
setDefaultTarget(generateSources)
This includes references and tasks from the GrailsCompile script, deletes some folders (in case you re-run this script), calls the compile task from the native grails gant, creates the necessary target folders
Copy the necessary jars to the grails lib folder. In my case I had to copy the aws-java-sdk-flow-build-tools-1.9.34.jar which includes the Annotation processor and another dependence freemarker-2.3.18.jar. Javac will automatically call the correct APT in order to process the annotations in the the folder src/java
Run the script
grails generateSources which will run the compile task and your new task
Open:
I'd like to hook up this task automatically when grails compile is called. I'm still working on that thoug.
Related
I am using Maven 3.x (3.2.5) and my project use the maven-antrun-plugin with additional dependencies. While I understand the principle behind, I have trouble understanding the use of <scope /> in this case:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<!-- executions -->
<dependencies>
...
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.17</version>
<scope>runtime</scope>
</dependency>
...
</dependencies>
</plugin>
I am depending upon mysql-connector-java with a runtime scope, whereas other dependencies use default (compile) scope.
The maven-antrun-plugin is used to do something to various database (hence the dependency). However, since the project is not tied to a specific JDBC Driver, the driver is not added to the project dependencies. The Ant task runs with several driver as dependencies since it may use such database depending on the configuration (eg: one could use jdbc:mysql, other jdbc:oracle:thin, etc...).
To my understanding, since the plugin executes, maven ignore the scope.
Is that true ?
Note: I've read the Maven documentation, and this point is not discussed. I'm pretty sure it is ignored but I'd like insight before.
What I would like to do is be able to put the version of my build into the maven command line and have that build version arrive in the MANIFEST.MF file. I was hoping to use the spring-boot-maven-plugin to do so.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--put something here from the command line? -->
</configuration>
</plugin>
I'm sorry that I haven't got a broken example for you to troubleshoot, but I can't seem to find any documentation on this the plugin usage examples that I have found don't cover anything like this.
I'm currently struggling with the maven site plugin. I have a corporporate/ super pom (packaging type pom) which defines all dependency version and also configures the site plugin. In addition I placed some image resources under /src/site/resources/images which are referenced in a custom site.xml (for example ./images/logo.jpg).
Another module references this parent pom and when I call mvn site it seems that the site.xml is getting picked up. But unfortunately the links to the images do not work. When I had a look in the target/site folder the images were missing. I also tried to create an additional 'corporate' resource module where I put the site resources (also under /src/site/resources), and reference this module as a dependency in the maven-site-plugin like this:
<build><plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>${maven-site-plugin.version}</version>
<dependencies>
<dependency>
<groupId>de.il</groupId>
<artifactId>build-tools</artifactId>
<version>${build-tools.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>attach-descriptor</id>
<goals>
<goal>attach-descriptor</goal>
</goals>
</execution>
</executions>
<configuration>
<reportPlugins>
<plugin>
....
But this does not seem to work either. It worked for other reporting modules like pmd with special configurations which were placed under /src/main/resources though...the site resources does not seemed to be picked up and published to the repository.
So the question is: How is it possible to attach images and stylesheets to a maven super pom? I'm using Maven 3 btw...
I have a bunch of maven projects that needs to execute the same sequence of ant tasks using the maven-antrun-plugin during the build/deploy phase.
I don't want to override the implementation of maven-antrun-plugin in a parent project so all other projects using this plugin will inherit these steps.
I was therefore looking into writing my own maven plugin that works as a maven-antrun-plugin wrapper with a special sequence of ant tasks. But currently I have had no success doing this.
I have looked at:
http://maven.apache.org/guides/plugin/guide-ant-plugin-development.html
but run into the same problem described here:
http://www.mail-archive.com/users#maven.apache.org/msg92676.html
(using the versions suggested in the above post does not solve the problem)
and from :
http://www.mail-archive.com/users#maven.apache.org/msg115264.html
it looks like the tutorial only works with maven2:
I have also tried to steal something from here:
http://maven.apache.org/guides/plugin/guide-java-plugin-development.html
but still no working plugin.
The plugin that I want to wrap looks like this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!-- execute task A,B and D -->
</tasks>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Is it possible to put the sequence of task A, B and C out in another plugin an then use that plugin where ever needed?
I have also tried to move the antrun plugin to a parent and the disable it for some of the children setting inheritance to false:
http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_inherited_Tag_In_Build_Plugins
but the task defined in the parent is still executed so setting the inheritance to false does not seem to work.
If you want to define a <plugin> in the parent and allow children to use it as appropriate, then you can define it within a <pluginManagement> section. By doing this, the parent will not execute the plugin. It will execute only for those children which define this plugin in their pom.
As for sequencing of ant tasks, would it not be simpler to create a task in your ant script, which calls the tasks A, B and C in sequence and continue to use the default maven-antrun-plugin functionality?
I'm trying to upload a file using an Ant task. If I use Ant directly the file is uploaded, but if I call the ant task via Maven (using the maven-antrun-plugin) I get the following error:
An Ant BuildException has occured: The following error occurred while executing this line:
/home/me/proj/build.xml:15: Problem: failed to create task or type ftp
Cause: the class org.apache.tools.ant.taskdefs.optional.net.FTP was not found.
This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
-ANT_HOME/lib
ant-commonsnet.jar is clearly available to Ant:
$ ls $ANT_HOME/lib | grep ant-commons-net
ant-commons-net.jar
Is the Ant classpath defined separately for maven-antrun-plugin, or am I missing something?
ant-commons-net.jar is clearly available to Ant
Yes, but Maven and the maven-antrun-plugin is not using your local Ant install.
Is the Ant classpath defined separately for maven-antrun-plugin, or am I missing something?
The way to use Ant Tasks not included in Ant's default jar is documented in Using tasks not included in Ant's default jar (which should definitely help):
To use Ant tasks not included in the
Ant jar, like Ant optional or custom
tasks you need to add the dependencies
needed for the task to run to the
plugin classpath and use the
maven.plugin.classpath reference if
needed.
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>my-test-app</artifactId>
<groupId>my-test-group</groupId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>ftp</id>
<phase>deploy</phase>
<configuration>
<target>
<ftp action="send" server="myhost" remotedir="/home/test" userid="x" password="y" depends="yes" verbose="yes">
<fileset dir="${project.build.directory}">
<include name="*.jar" />
</fileset>
</ftp>
<taskdef name="myTask" classname="com.acme.MyTask" classpathref="maven.plugin.classpath"/>
<myTask a="b"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-commons-net</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
As Pascal has mentioned, the maven-antrun-plugin is not using the ant specified by your $ANT_HOME environment variable, and the configuration that he's mentioned is probably the best way to do it consistently from a pure maven perspective.
However, the jar can be stored in $USER_HOME/.ant/lib instead of $ANT_HOME/lib, these jars should be available on the classpath for any instance of ant that is run by that user.
Note that your ant script cannot assume that the jars are present, and that the jars are only placed on the classpath at startup, so if the script defines a setup target to download the jars into $USER_HOME/.ant/lib, then this target would have to be run in a "separate-ant-session", before and is invoked again to execute the task that depends on the jar.
The only potential benefit that you may derive from this approach is that the Ant script may be runnable from maven and Ant.
There is a classpath property which can be set in <tasks> section of maven-antrun-plugin.
For instance,
<property name="classpath" refid="maven.compile.classpath"/>