I always used succesfully ANTLR4 combined with Maven inside Eclipse.
I just want to change the default directory where I store my grammar, since I do not like the standard path which is src/main/antlr4. The issue of this path is the creation of a new java package, that I really do not want.
So I simply decided to create another directory inside my project named grammar which contains another directory called imports. I did this following simply the website guidelines.
Despite this, when I change the grammar it doesn't generate automatically the new sources, even with the maven commands!
So, this is my configuration file pom.xml:
<!-- ANTLR4 -->
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.5.3</version>
<executions>
<execution>
<configuration>
<goals>
<goal>antlr4</goal>
</goals>
<libDirectory>grammar/imports</libDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
As you can see, the target directory is empty. Before this change, there was a generated-sources directory inside with all the .java files.
So, where is the error?
The correct way is:
<!-- ANTLR4 -->
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.5.3</version>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
<configuration>
<libDirectory>grammar/imports</libDirectory>
</configuration>
</execution>
</executions>
</plugin>
The <configuration> tag must be at same level than <goals> tag, inside <execution> tag, according to Maven documentation: https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_executions_Tag and https://maven.apache.org/guides/mini/guide-default-execution-ids.html
In fact, the documentation in ANTLR4 Maven plugin is wrong:
http://www.antlr.org/api/maven-plugin/latest/examples/libraries.html
Related
The following plugin added to the pom.xml allows source-jar to be created when performing mvn package:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
The usage of the scala-maven-plugin is :
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArgs>
<jvmArg>-Xmx12g</jvmArg>
</jvmArgs>
<args>
<arg>-feature</arg>
<arg>-deprecation</arg>
<arg>-target:jvm-1.7</arg>
</args>
</configuration>
</plugin>
However only the java sources are being included: the scala sources are left out. Note that we are using the standard maven directory layout. In particular we have scala sources here:
src/main/scala
So - are there additional options to the maven-source-plugin to encourage it to invite the scala classes to participate? Or a different scala-specific plugin and/or option to get them onboard?
The jar goal of the Maven Source Plugin will bundle all of the sources of the Maven project into a JAR. You can select what to include or exclude in those source folders (with the includes and excludes parameters), but you cannot add whole new source folders to it; they must be added as source folders of the Maven project itself.
When you have a pure Scala project, src/main/scala and src/test/scala are declared as source folders, because you would have:
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
in your POM, overriding the default src/main/java and src/test/java. So the Maven Source Plugin would correctly add the sources present in those two folders without additional configuration.
But when you have a mixed Java / Scala project, the <sourceDirectory> and <testSourceDirectory> element are typically left in to their default values. This does not create any problems with regard to compiling or running Scala code with the plugin, as it looks up the files by default in ${project.build.sourceDirectory}/../scala. However, other unrelated Maven plugins can't know about those new folders.
To fix this, the plugin provides the add-source goal, which adds src/main/scala and src/test/scala as source and test source directory to the Maven project, and, thus, makes them available for the other plugins relying on the source directories, like the Maven Source Plugin. You should therefore change your POM to:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<!-- rest of configuration -->
</plugin>
I need to create a list of subclasses for a particular interface during maven build process and then use that at runtime to load those classes. I have added reflections-maven (from google code reflections) in my webapp pom but during maven build, its only including the classes from the web application and not the classes inside the packaged jars that are there in web-inf/lib folder of that application. Below is the straight forward configuration I have used. I looked at the plugin source code and it seems it scans the following: getProject().getBuild().getOutputDirectory().
Is there anyways I can configure the plugin to scan the dependent jar files of the project?
<plugin>
<groupId>org.reflections</groupId>
<artifactId>reflections-maven</artifactId>
<version>0.9.9-RC1</version>
<executions>
<execution>
<goals>
<goal>reflections</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
You can easily run Reflections with any configuration you like, using, for example, gmaven-plugin:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9-RC1</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
new org.reflections.Reflections("f.q.n")
.save("${project.build.outputDirectory}/META-INF/reflections/${project.artifactId}-reflections.xml")
</source>
</configuration>
</execution>
</executions>
</plugin>
So all you need to do is to use the right configuration, maybe in your specific case:
def urls = org.reflections.util.ClasspathHelper.forWebInfLib()
new org.reflections.Reflections(urls)
.save("${project.build.outputDirectory}/META-INF/reflections/${project.artifactId}-reflections.xml")
How can I add a prefix directory so when I unpack the zip containing my RCP app I get a directory containing the contents?
When tycho materalizes and archives my rcp app it zips up target/products/my.rcp.app/linux/gtk/x86_64/ contents without a directory prefix.
Current zip contents:
./features
./plugins
...
Desired zip contents:
./myapp/features
./myapp/plugins
...
When a user unpacks the zip, I'd like the app directory to be created. I looked through the tycho docs but neither archive nor materialize seems the right place to configure this. I could always use antrun or assembly plugin to do the work but that doesn't feel like the right maven way to solve the problem.
Please let me know how to add a prefix directory.
The configuration is really a bit messed up and not really documented. Since you (currently) can have multiple product files in one eclipse-repository module, you need to select the product ID for which you want to apply the configuration.
So to set the archive root folder for the product with ID product.id, you need the following configuration:
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>materialize-products</id>
<goals>
<goal>materialize-products</goal>
</goals>
</execution>
<execution>
<id>archive-products</id>
<goals>
<goal>archive-products</goal>
</goals>
</execution>
</executions>
<configuration>
<products>
<product>
<id>product.id</id>
<rootFolder>myapp</rootFolder>
</product>
</products>
</configuration>
</plugin>
</plugins>
</build>
Thanks but I needed to use the rootFolder option to add the extra directory. I tried injecting achivePrefix into the .product file but that didn't work. I finally broken down, grabbed tycho source and worked backwards to find rootFolder. After this journey, I saw it in the doc and grocked the meaning.
Doc: http://wiki.eclipse.org/Tycho/Packaging_Types#Creating_Product_Zip_Files
Related: https://issues.sonatype.org/browse/TYCHO-507
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<products>
<product>
<id>match-product-uid-field-from-foo.product-file</id>
<rootFolder>workbench</rootFolder>
</product>
</products>
</configuration>
<executions>
<execution>
<!-- install the product using the p2 director -->
<id>materialize-products</id>
<goals>
<goal>materialize-products</goal>
</goals>
</execution>
<execution>
<!-- create zip file with the installed product -->
<id>archive-products</id>
<goals>
<goal>archive-products</goal>
</goals>
<configuration>
<formats>
<linux>tar.gz</linux>
<win32>zip</win32>
</formats>
</configuration>
</execution>
</executions>
</plugin>
I have a workspace with multiple projects. All are Maven projects. The target directory of one of the projects contains a batch file after it is built. Now, I need one of the other projects in the workspace to run this batch file. So, I want to get the path to the current workspace programmatically without introducing new dependencies to accomplish this. Does anybody know of a way to do this?
Edit 1: I have a parent Maven project in the workspace. One of its children's target directory contians the batch file. A different child of the parent (which is a testing project) needs to run the batch file. I can use the Maven basedir variable to get the batch file which isn't pretty and doesn't work if I am running individual tests with Eclipse. So I'd like to avoid that solution.
The problem you'll have is that projects in Eclipse aren't necessarily stored in the workspace directory; they could be anywhere on the file system. This means that simply knowing where the workspace is won't necessarily help you find the batch file.
For example: my workspace is $HOME/workspace, but all my projects (the working copies) are in $HOME/code/project. Being able to determine the workspace isn't very helpful. Projects can exist outside the workspace, and still appear in Eclipse by using File -> Import.
Your best bet is probably to 'attach' the batch file to the build using the attach-artifact goal of build-helper-maven-plugin. There's an example of how to do that here.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>script.bat</file>
<type>bat</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Then, your other project can use the copy goal of maven-dependency-plugin to resolve the script into its own directory and run it from there.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<type>bat</type>
<overWrite>true</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/scripts</outputDirectory>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
How about the maven-antrun-plugin? It's not pretty, but it gets the job done:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id><!-- insert an id --></id>
<phase><!-- insert a maven lifecycle phase --></phase>
<configuration>
<tasks>
<exec
dir="${basedir}"
executable="${basedir}/src/main/sh/your-script.sh"
failonerror="true">
<arg line="arg1 arg2 arg3" />
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Ref: http://maven.apache.org/plugins/maven-antrun-plugin/usage.html
When the build is ready i have p2 folder in all build archives for different platforms.As i understand it's imposible to exclude p2 directory from archives on building stage. So I try pack archive myself instead of using archive-products execution.
The problem is if i want to make archives for others platform or architecture I will need to change pom.
Now i have the following build schema:
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>materialize-products</id>
<goals>
<goal>materialize-products</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>pack-zip-files</id>
<phase>package</phase>
<configuration>
<target>
<zip basedir="${project.build.directory}/products/xxx/win32/win32/x86"
destfile="${project.build.directory}/products/xxx-1.0.${BUILD_NUMBER}-win32.win32.x86.zip"
excludes="${exclude_p2}" />
<zip basedir="${project.build.directory}/products/xxx/linux/gtk/x86"
destfile="${project.build.directory}/products/xxx-1.0.${BUILD_NUMBER}-linux.gtk.x86.zip"
excludes="${exclude_p2}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The quiestion is how to remove p2 folder from all zip files?
What you are doing now is really the only way to do it. You could change the packaging type to eclipse-application and that directory won't be created, but it is a deprecated packaging type and has a whole slew of problems.
The only way to help with multiple POM support would be to put that POM configuration into a profile and have your projects that build products inherit from it. You can also use the osgi.os osgi.arch properties in place of hard-coding things like win32 and linux.