I'm building a Java Camel project using Maven 3.3.9 and Camel 2.19.5, everything compiles, but on validation Maven fails with the error below. Looks like Spring boot is trying to auto-configure something. The project is not a typical Springboot app, it's a custom Maven plugin that happens to depend on Camel. My suspicion is Maven's expecting to find main() in the code but it does not exist since the project has no runnable main(). Anyway, that's what I think, it's a nasty issue I'll tell ya that.
[INFO] BUILD FAILURE
[INFO] ----------------------------------------------------
[INFO] Total time: 10.344 s
[INFO] Finished at: 2018-06-22T16:13:41-04:00
[INFO] Final Memory: 39M/622M
[INFO] ----------------------------------------------------
[ERROR] Failed to execute goal
org.apache.camel:camel-package-maven-plugin:2.19.5:
prepare-spring-boot-auto-configuration
(validate) on project ofi-salesforce-maven-plugin:
Execution validate of goal org.apache.camel:camel-package-maven-plugin:2.19.5:
prepare-spring-boot-auto-configuration
failed: Cannot find Apache Camel project root directory
Figured it out; the code was previously using Camel 2.15.1, but after upgrading to Camel 2.19.1 we failed to consider Maven build changes. Since our code is branched from Camel Salesforce Maven plugin, the pom for that project now includes camel-package-maven-plugin, which we failed to include in our pom. The plugin skips validation phase, and that's where the error was happening, makes sense.
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-package-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare</id>
<phase>none</phase>
</execution>
<execution>
<id>validate</id>
<phase>none</phase>
</execution>
<execution>
<id>readme</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
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.
So, I'm trying to use the latest version of some plugins. Earlier I've used the prerequisites-tag but lots of resources (example) say that it should be considered deprecated and that the maven-enforcer-plugin should be used instead.
this is my configuration:
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-maven-3</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.0.4</version>
</requireMavenVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
However, when I run mvn versions:display-plugin-updates I still get this text:
[ERROR] Project does not define required minimum version of Maven.
[ERROR] Update the pom.xml to contain
[ERROR] <prerequisites>
[ERROR] <maven>3.0</maven>
[ERROR] </prerequisites>
[INFO]
[INFO] Require Maven 2.0.6 to use the following plugin updates:
[INFO] maven-jar-plugin ................................................ 2.4
[INFO] maven-shade-plugin ............................................ 1.7.1
[INFO]
[INFO] Require Maven 2.2.1 to use the following plugin updates:
[INFO] maven-jar-plugin ................................................ 2.6
[INFO]
[INFO] Require Maven 3.0 to use the following plugin updates:
[INFO] maven-shade-plugin .............................................. 2.3
Using the prerequisites-tag instead works.
It seems like this issue has been reported here (credits go to Aleksandr M for finding this).
Apparently, the display-dependency-updates goal relies on the prerequisites element to find out the Maven version required by the current project and totally ignores the enforcer-plugin, even though the prerequisites-tag should not be used normally, it is required in order to get the dependency plugin to behave as expected.
To avoid this message I use last version of versions-maven-plugin
mvn org.codehaus.mojo:versions-maven-plugin:2.7:display-plugin-updates
Note that it still requires either use of maven-enforcer-plugin for all but maven-plugin projects, or use of prerequisites tag for projects with maven-plugin packaging.
The prerequisites is deprecated for Maven 3.X:
http://jira.codehaus.org/browse/MNG-4840
http://jira.codehaus.org/browse/MNG-5297
Furthermore if you call
mvn versions:display-plugin-updates
you are not starting a life cycle whereas the configuration of your maven-enforcer-plugin is bound to the life cycle.
Furthermore you should pin all versions of the plugins you are using in your build.
And one very important things (excerpt from the FAQ):
The prerequisites tag was designed to be used by tools like plugins.
It will work for regular projects, but it isn't inherited to their
children. If it is set in a parent reactor, then Maven will do the
check. However if one of the children are built, the check is not
performed. The enforcer plugin is designed to allow centralized
control over the build environment from a single "super-pom", and to
allow greater flexibility in version specification by supporting
ranges.
This means only if your developing plugins the prerequisites does make a limited sense better to use the maven-enforcer-plugin path. For usual development project use the maven-enforcer-plugin configuration way to force particular Maven versions.
To stay informed about plugin update i can recommend to subscribe to the Announcment mailing list or if you like to get a good overview see the plugins page.
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