I have created a maven android project using this archetype. I want to integrate mirah source files inside my project. So I added the plugin mentioned here to my pom.xml. I setup the configuration section for the plugin to point the source directory to src/main/mirah.
But when I run mvn compile it only compiles the sources inside src/main/java. I have tried running it with mvn -X compile to try and debug the issue, but I can't find anything related to mirah or the mirah-maven-plugin there.
Using the archetype it created two projects - project and project-it (tests) , there is a pom.xml in the root directory as well as a pom.xml in project and project-it directories. I have tried the above configurations in both the root directory as well as in project's pom.xml.
I have come across this question related to using the build-helper plugin but I don't know if it will help in my case. Since my mirah plugin isn't getting called at all.
Is this the right way to do what I'm trying to do? Any help on the setup, or pointer to how to troubleshoot this would be much appreciated.
The relevant bit of my pom.xml
<plugin>
<groupId>org.mirah.maven</groupId>
<artifactId>maven-mirah-plugin</artifactId>
<version>1.0</version>
<configuration>
<sourceDirectory>src/main/mirah</sourceDirectory>
<outputDirectory>target/classes</outputDirectory>
<bytecode>true</bytecode>
<verbose>false</verbose>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals><goal>compile</goal></goals>
</execution>
</executions>
</plugin>
Edited as per answer below.
I have added the source directory using the build-helper plugin and I'm able to get the mirah sources to compile using mvn org.mirah.maven:maven-mirah-plugin:1.0:compile from the answer below. But mvn compile still only compiles the sources in src/main/java and not src/main/mirah.
For anyone interested in the output of mvn -X compile here is the pastie.
This page https://github.com/calavera/maven-mirah-plugin#readme says that the mirah plugin extends the default compiler plugin. So this would suggest that the build helper plugin would work for multiple source directories, if it works for the default compiler plugin.
Looking at the mirah plugin, you probably don't need to specify sourceDirectory and outputDirectory yourself, as it seems you're using the defaults.
The -X switch won't have any impact on the mirah plugin directly, as it doesn't do any tracing itself (above what the default compiler plugin does).
Can you show your -X output anyway to show that the mirah plugin isn't invoked?
Alternatively, you could build the mirah plugin yourself and add tracing. It doesn't seem a complicated plugin.
What happens when you try and invoke the plugin directly? E.g.
mvn org.mirah.maven:maven-mirah-plugin:1.0:compile
EDIT:
Tried it myself and this works for me (by 'works' I mean the plugin gets invoked - my build actually fails).
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>temp</groupId>
<artifactId>temp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.mirah.maven</groupId>
<artifactId>maven-mirah-plugin</artifactId>
<version>1.0</version>
<configuration>
<bytecode>true</bytecode>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
With this output:
D:\dev\workspaces\3.6\temp>mvn compile
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - temp:temp:jar:0.0.1-SNAPSHOT
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [mirah:compile {execution: default}]
[INFO] No sources to compile
Parsing...
D:\dev\workspaces\3.6\temp\src\main\mirah/test.mirah
Inferring types...
* [Mirah::Typer] Learned local type under #<Mirah::AST::StaticScope:0xbc5245> : a = Type(int)
... ETC ...
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Unknown error - Unknown Error (20047) - D:\dev\workspaces\3.6\temp\target\classes\D:
I don't know what the error means as I'm not a mirah user.
Related
I wrote a custom maven plugin that scaffolds java-code from a custom schema.
The project-structure is like this:
Project
+ plugin
+ web-application
The reactor compiles first the plugin, then the application.
The usual mvn-command is:
mvn
... who is triggering the <defaultGoal>plugin:scaffold package</defaultGoal>
On fresh machines the build fails because the plugin is not yet known at the time the reactor plan the build-phases. So I have to call mvn install first. Then mvn plugin:scaffold package works like a charm.
The problem is: Whenever I modify the scaffolder-plugin and call mvn plugin:scaffold package the modifications of the scaffolder-plugin is not yet used because it is not yet installed into the repository. So I have to call mvn install first again.
Is there a way to:
Install the modification to the plugin
Build the webapplication using the modifications of the plugin
in one step?
First your plugin must be a module of the root project for the resolution to work correctly:
<modules>
<module>plugin</module>
<module>app</module>
</modules>
Then declare the plugin in the build/plugins section your application pom
<build>
<plugins>
<plugin>
<groupId>org.example.plugin</groupId>
<artifactId>plugin</artifactId>
<version>${project.parent.version}</version>
<executions>
<execution>
<id>sayhi</id>
<phase>generate-sources</phase>
<goals>
<goal>sayhi</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The first time you run the plugin or when the plugin changes you need to run at least the package phase so the plugin jar is created. It must be run from the root project:
mvn package
The plugin will be executed during the generate-sources phase:
[INFO] --- plugin:1.0-SNAPSHOT:sayhi (sayhi) # app ---
[INFO] Hello, world.
[INFO]
When you change the plugin just run (again from root project):
mvn package
and you will see the changes:
[INFO] --- plugin:1.0-SNAPSHOT:sayhi (sayhi) # app ---
[INFO] Hello, worldxxxx.
[INFO]
See a full example on Github
I'm using this Github project to get exposed to the new modular features in Java 9. I would like to add dependencies to the project and be able to build a native image. However, when I try to add a new dependency to the pom.xml, and add the requires statement to the module-info.java, I get a the following error from the maven-jlink-plugin:
Error: module-info.class not found for joda.time module
I'm trying to use this as a proof of concept that I can deploy images using the new linking phase, but naturally I need to be able to have external dependencies and I need to use maven (work constraint).
Changes to mod-jar/pom.xml
...
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.9</version>
</dependency>
</dependencies>
...
mod-jar/module-info.java
module com.soebes.nine.jar {
requires java.base;
requires joda.time;
exports com.soebes.example.nine.jar;
}
Logs:
[INFO] --- maven-jlink-plugin:3.0.0-alpha-1:jlink (default-jlink) # mod-jlink ---
[INFO] Toolchain in maven-jlink-plugin: jlink [ /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin/jlink ]
[INFO] The following dependencies will be linked into the runtime image:
[INFO] -> module: com.soebes.nine.one ( /Users/sebastianrestrepo/Projects/jdk9-jlink-jmod-example/maven-example/mod-1/target/jmods/com.soebes.nine.one.jmod )
[INFO] -> module: com.soebes.nine.two ( /Users/sebastianrestrepo/Projects/jdk9-jlink-jmod-example/maven-example/mod-2/target/jmods/com.soebes.nine.two.jmod )
[INFO] -> module: com.soebes.nine.jar ( /Users/sebastianrestrepo/Projects/jdk9-jlink-jmod-example/maven-example/mod-jar/target/com.soebes.nine.jar-1.0-SNAPSHOT.jar )
[INFO] -> module: joda.time ( /Users/sebastianrestrepo/.m2/repository/joda-time/joda-time/2.9.9/joda-time-2.9.9.jar )
[ERROR]
Error: module-info.class not found for joda.time module
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent ............................................. SUCCESS [ 1.460 s]
[INFO] com.soebes.nine.one ................................ SUCCESS [ 2.022 s]
[INFO] com.soebes.nine.two ................................ SUCCESS [ 1.392 s]
[INFO] com.soebes.nine.jar ................................ SUCCESS [ 1.388 s]
[INFO] mod-jlink .......................................... FAILURE [ 1.061 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.911 s
[INFO] Finished at: 2017-11-03T15:27:35-04:00
[INFO] Final Memory: 26M/981M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jlink-plugin:3.0.0-alpha-1:jlink (default-jlink) on project mod-jlink:
I would really appreciate any help. Thanks.
This has not much to do with the plugin I believe. Module joda.time in your case seems to be an automatic module.
The jlink tool does not support linking of automatic modules because they can rely on the arbitrary content of the classpath, which goes against the idea of a self-contained Java runtime.
So there are two ways to fix this probably :-
(you don't own the jar) Temporarily go ahead create a module-info.java[you could use jdeps tool for it] and update the jar[using jar tool] with the corresponding compiled class as in projects under Java 9.
(you own the dependency) Permanently migrate the jar to Java 9 itself, where it would consist of the module-info.class by itself after being compiled and packaged.
You could use the ModiTect Maven plug-in to add a module descriptor to the JAR and create a modular runtime image with that module.
Disclaimer: I'm the author of ModiTect.
Let me try to explain the technical background on this a little bit:
joda-time in the version 2.9.9 as given in the question is a non-modular jar it does not contain a module-info.class and it does not declare itself as an automatic module by using a Automatic-Module-Name: in its META-INF/MANIFEST.MF
Classes in a real module can not call classes on the classpath thus you can not use the "requires jode.time" in your module-info with that version.
Automatic Modules can use classes on the ClassPath. In order to use Classes from an non-modular jar in a real module you can use a wrapper which itself is an automatic module.
By the time now there exists a version 2.10.1 of joda-time which is an automatic module and declares "Automatic-Module-Name: org.joda.time" thus you can use an "requires org.joda.time" in your real module with that new version.
Now the new jlink tool can not operate directly with non-modular jars or automatic jars and the maven-jlink plugin currently is basically just a maven wrapper around the jlink tool translating its configuration parameters into arguments for the jlink tool.
In order to create a custom Java Runtime for projects using mixed maven dependencies with real modules, automatic modules and non-modular jars you have to know all system module dependencies of your real-modules, automatic-modules and non-modular jars and than use a --add-modules parameter to jlink with these.
To collect the system module dependencies you can use the new jdeps tool with either the --print-module-deps or --list-deps parameter depending on the actual JDK Version being used.
If you are using maven for your project you can automate that task by creating or using a maven plugin that does this for you.
I had a similar problem in one of my projects. First, I tried the moditect-maven-plugin, which worked great! However, with this plugin you have to configure each dependency that is missing a module descriptor separately. If you have many dependencies missing a module descriptor, this can get cumbersome.
Therefore, I decided to develop a new maven plugin, the jigsaw-maven-plugin (see https://github.com/ghackenberg/jigsaw-maven-plugin). The plugin provides three goals for patching all unnamed modules (see Step 3) as well as linking and packaging these modules (see Steps 4 and 5).
Before patching, linking, and packaging, you need to build the project JAR (see Step 1) in and copy the project dependencies (see Step 2) to a common location (e.g. ${project.build.directory}/modules). Maybe you can use the following build plugin configurations to get started (see GitHub page for more details):
Step 1: Build archive
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
</configuration>
</plugin>
Step 2: Copy dependencies
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Step 3: Patch all unnamed modules
Search for JARs in modulePath missing a module descriptor, generate missing module descriptors using jdeps and javac, and add them to respective JARs using java.util.zip.
<plugin>
<groupId>io.github.ghackenberg</groupId>
<artifactId>jigsaw-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>patch</goal>
</goals>
<configuration>
<modulePath>${project.build.directory}/modules</modulePath>
</configuration>
</execution>
</executions>
</plugin>
Step 4: Link modules
Link modules using jlink.
<plugin>
<groupId>io.github.ghackenberg</groupId>
<artifactId>jigsaw-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>link</goal>
</goals>
<configuration>
<modulePath>${project.build.directory}/modules</modulePath>
<module>your.module.name</module>
<output>${project.build.directory}/image</output>
</configuration>
</execution>
</executions>
</plugin>
Step 5: Package modules
Package modules using jpackage.
<plugin>
<groupId>io.github.ghackenberg</groupId>
<artifactId>jigsaw-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
<configuration>
<modulePath>${project.build.directory}/modules</modulePath>
<runtimeImage>${project.build.directory}/image</runtimeImage>
<mainClass>your.module.name/your.package.Main</mainClass>
</configuration>
</execution>
</executions>
</plugin>
I'm working in a Maven multimodule project and I'm not able to download javadocs for some dependencies. I'll describe my failed attempts:
I'm working with Netbeans so the first option was Right click in Dependencies -> Download Javadocs and some javadocs were dowoloaded but some other not.
Next option was to use mvn eclipse:eclipse but the result was the same (some javadocs were still missing). Also I saw that mvn eclipse plugin is deprecated
Last option was to use mvn dependency:resolve -Dclassifier=javadoc but the result is the same
I configured the maven-javadoc-plugin in my pom.xml but nothing happens. The configuration is the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
I don't want to use this option because implies a manual downloading. The third option gave me the following output:
[INFO] The following files have NOT been resolved:
[INFO] dom4j:dom4j:jar:javadoc:1.6.1:test
[INFO] org.jboss:jandex:jar:javadoc:1.1.0.Final:test
[INFO] org.hibernate:hibernate-entitymanager:jar:javadoc:4.3.1.Final:test
[INFO] org.hibernate:hibernate-validator:jar:javadoc:5.2.4.Final:provided
[INFO] xml-apis:xml-apis:jar:javadoc:1.0.b2:test
[INFO] org.hibernate.common:hibernate-commons-annotations:jar:javadoc:4.0.4.Final:test
[INFO] org.hibernate:hibernate-core:jar:javadoc:4.3.1.Final:test
[INFO] antlr:antlr:jar:javadoc:2.7.7:test
[INFO] javax.activation:activation:jar:javadoc:1.1:provided
Any help is appreciated, also if someone tells me that there's no other option but to install the artifacts manually.
Thanks in advance.
I need to build my Grails project with Maven, and it is necessary to add an additional grails command. I'm using the grails-maven-plugin to create the pom file, and I can build the war file with $ mvn package
While building this application, I will need to execute another grails command, one the does not correspond directly to any of the maven build phases. Referring to the docs, I'm adding a second execution element to the grails-maven plugin, as follows:
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>${grails.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>init</goal>
<goal>maven-clean</goal>
<goal>validate</goal>
<goal>config-directories</goal>
<goal>maven-compile</goal>
<goal>maven-test</goal>
<goal>maven-war</goal>
<goal>maven-functional-test</goal>
</goals>
</execution>
<execution>
<id>stats</id>
<phase>init</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<command>stats</command>
</configuration>
</execution>
</executions>
</plugin>
For this example I'm trying to execute grails stats in the maven init phase. (Eventually, stats will be replaced by something more useful.) when I run:
$ mvn package
the ouput includes:
[INFO] [grails:validate {execution: default}]
[INFO] [grails:init {execution: default}]
[INFO] [grails:config-directories {execution: default}]
[INFO] [resources:resources {execution: default-resources}]
which evidently doesn't contain the execution of grails stats. I am able to execute the stats command through Maven directly, in the following way:
$ mvn grails:exec -Dcommand=stats
it only fails to execute when added as a goal in the pom.
I'm using Java 1.5.0_22, Grails 1.3.7, and Maven 2.2.1.
Based on the information I could find about this plugin, you should add the grails: prefix to your goals.
I have no experience with this plugin, so I could be wrong =)
References:
http://grails.1312388.n4.nabble.com/grails-maven-plugin-version-td2284532.html
http://www.grails.org/Maven+Integration
so for example: <goal>grails:init</goal>
OK, my problem was confusing goals and Maven phases. Notice I was trying
<phase>init</phase>
and I had tried other items from the list of goals, but these are not Maven phases.
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
Given a <plugin> element in a pom.xml, how do I find the default phase that it binds to?
For example, I'd like to know which phase of the Maven lifecycle does the maven-war-plugin gets executed.
The best way to see what's really happening in your project along those lines is with mvn help:effective-pom. It doesn't just show the defaults; it shows what actually is according to your current pom.
I'm having a problem with the above-reply.
Here's a simple pom. It uses an annotation processor plugin, which is bound to generate-sources by-default, since I didn't specify a <phase>.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test-simple</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.0.5</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
mvn generate-resources does indeed invoke the plugin...
$ mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-simple 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-processor-plugin:2.0.5:process (default) # test-simple ---
Yet scanning the output of mvn help:effective-pom doesn't yield any clue to the default binding of this plugin.
$ mvn help:effective-pom |grep generate-sources; echo $?
1
The only way I've so-far found to list default phase binding is by examining plugin source.