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>
Related
pom.xml:
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
</execution>
</executions>
</plugin>
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
Code structure:
src/main/java
Hello.java
src/main/scala #will reference the class under /src/main/java
App.scala
IDE : Intellij IDEA 2017.2.1 , JDK: java8
Issues :
when ever i run the maven compile via the intellij, it always show below errors, which means it can not find the Hello.class .
Questions:
why this pom.xml does not work ? I checked the doc of scal-maven-plugin, the layout should work, but it did not .
I found it will work if i add the src/main/java as source directory via the build-helper-maven-plugin. This may explain the first question, but i realized that before the maven compile, i run the App.scala via the Intellij , so the Hello.java has already been compiled to class and i could see it under the src/main/target/classes . So Why the scala-maven-plugin can not find the class under src/main/target/classes ?
like in the documentation/sample linked in the question, remove
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
or set them to src/.../java (the default values), no need to use the build-helper-maven-plugin
or place *.java and *.scala under the same directory (my favorite)
In dual mixed java/scala (scala depends on java and java depends of scala), the scala compiler run against java source, not from binary.
If you want to "notify" the IDE that scala source are under src/.../scala "add"
<goal>add-source</goal>
see add-source
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
Can someone recommend a basic pom.xml file for a Scala project on Maven? So far, none of the options I get from mvn archetype:generate seems to be as basic as I would like. I want only the dependencies and plugins that are absolutely required to run a Scala jar.
The scala-maven-plugin is the only friend you need, basically add this plugin to your pom.xml:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
You might be interested in adding some configuration or execution parts to it, but you can read more about it on their website: http://davidb.github.io/scala-maven-plugin/
We have a relatively large project. One of the modules has 30 generated GWT message bundles.
It takes 2 seconds to generate each bundle, so 2*30 = 1 minute.
I think it's because of big classpath, because the project has a lot of dependencies and they all added to gwt.
In fact, only the src/main/java is needed for the generation. Can I somehow configure the plugin's classpath? For example, the Surefire plugin has classpathDependencyExcludes and additionalClasspathElement, but there's no universal option for all plugins. Right?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt.mvn.plugin}</version>
<executions>
<execution>
<goals>
<goal>i18n</goal>
</goals>
</execution>
</executions>
<configuration>
<generateDirectory>${basedir}/src/main/java</generateDirectory>
<i18nMessagesBundles>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.SmpMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.PrepaymentFormMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.DebitorFinanceStateMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.AttributeAnalyticAccountsMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.SearchCustomerAccountsMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.LoanRatingQualityMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.RegistrationOfContractMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.BalancesAccountTurnoverMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.RegistrationClientAccountsMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.PackTermsDialogMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.OtherLoansMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.RatingQualityControlMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.ActualDebitorPacksTableMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.RegCredDecisionMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.PaymentGrafsMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.RestructuringRegistrationMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.CancelFinishContractAccountingMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.CompletionOfContractAccountingMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.PackInfoMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.RenewalRegistrationMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.ReserveLoanAccountMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.RatingWithDeprecMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.ReserveLoanAccaOrderMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.LoanAccountAttributesMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.EkkEndorsementsMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.ReportHeadingsMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.DocumentDetailsMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.ContractChoiceMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.ZvaWObspRaspPrintListMessages</i18nMessagesBundle>
<i18nMessagesBundle>ru.sbrf.iask.client.i18n.TransmitToProcessAlkLimitsMessages</i18nMessagesBundle>
</i18nMessagesBundles>
</configuration>
</plugin>
I'am trying to setup eclipse environment to develop bundles (With maven-bundle-plugin-bnd)
and run & debug that bundles equinox from eclipse
I created sample bundles with org.apache.felix maven-bundle-plugin and can install and start that bundles from eclipse equinox,
but every time i need to run "install file:C:\path\bundle1.jar","install file:C:\path\bundle2.jar" which causes pain. i searched for run configuration but it only intalls and starts (plugin) projects in workspace not maven projects.
What i have done is create maven project and add dependencies(bundle1,bundle2 etc..) and added maven-dependency-plugin to copy all depended bundles in one folder (another problem is equinox use "_" delimeter to determine version of bundles but maven uses "-" as delimeter) if i do not strip version in standalone equinox application i need to give version of bundle in config.ini file but i dont want that, is this proper way to solve this problem?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${bundleDirectory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
To sum up , i have bundles in folder, which is created with org.apache.felix maven-bundle-plugin , how can i run and debug them from eclipse?
I wouldn't say this is a "proper" solution, but it may work for you.
The antrun plugin can be used to modify the dependencies to replace the final hyphen with an underscore, so the dependency plugin doesn't need to strip the version.
My regex is rusty, but from a little testing the following configuration appears to apply the required name change to the files in the bundleDependency directory.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${bundleDirectory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<!-- move within same directory is preferred method for a rename-->
<move todir="${bundleDirectory}">
<fileset dir="${bundleDirectory}"/>
<mapper type="regexp" from="([a-zA-Z0-9\.-]+)(-)([0-9\.]+.jar)"
to="\1_\3"/>
</move>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
</plugin>
I wrote a tool called auto-builder (http://code.google.com/p/auto-builder). It introspects PDE-based projects and generates Ant build files; it supports transitive closure over dependencies and all that jazz.
I posted a write-up: http://empty-set.net/?p=9. I wrote it because the Maven tools I played with, when integrated with PDE, didn’t “just work.” Basically, I wanted to do coding in PDE and have a Hudson-based CI without any fuss in between.
Generating Ant files is nice because it gives you all the benefits of a declarative build tool, but it leaves you with a procedural description of what it is doing.
I am looking for more PDE-based projects to test it on. There are a couple RFC-0112 Bundle repositories around, and I have some code for downloading dependencies. If anyone is interested, then I could integrate dependencies download with auto-builder.