I have two maven modules:
native-wrapper - is a JNI wrapper over system lib, that is build by nar-maven-plugin.
main-module - depends on native-wrapper and uses it's JNI calls during tests.
Tests in native-wrapper work fine. But, during tests in main-module, I get "UnsatisfiedLinkError" - NarSystem is unable to locate my JNI lib.
native-wrapper's pom includes:
...
<packaging>nar</packaging>
...
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.0.0-rc-2</version>
<extensions>true</extensions>
<configuration>
<libraries>
<library>
<type>jni</type>
<narSystemPackage>some.native.wrapper</narSystemPackage>
</library>
</libraries>
</configuration>
</plugin>
I opened generated .nar in ./target/ - it does contain "/lib/amd64-Linux-gpp/jni/libnative-wrapper-0.1.0-SNAPSHOT.so". The other nar (with java classes) contains "/META-INF/nar/some.native.wrapper/native-wrapper/nar.properties".
main-module's pom:
...
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>native-wrapper</artifactId>
<version>${project.version}</version>
<type>nar</type>
</dependency>
...
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.0.0-rc-2</version>
<extensions>true</extensions>
</plugin>
If I remove nar-maven-plugin plugin from main-module's pom, maven does not find any classes from native-wrapper module.
How can I make nar find the lib?
It seems like, one can't just add artifact with <type>nar</type> and run tests. You should set proper library path for java yourself. I did it like this (in addition to main-module's pom):
<packaging>nar</packaging>
...
<properties>
<LIBRARY_PATH>${project.build.directory}/nar/native-wrapper-${project.version}-amd64-Linux-gpp-jni/lib/amd64-Linux-gpp/jni/:${project.build.directory}</LIBRARY_PATH>
</properties>
...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<environmentVariables>
<LD_LIBRARY_PATH>${LIBRARY_PATH}</LD_LIBRARY_PATH>
<DYLD_LIBRARY_PATH>${LIBRARY_PATH}</DYLD_LIBRARY_PATH>
</environmentVariables>
<systemProperties>
<property>
<name>java.library.tmpdir</name>
<value>${LIBRARY_PATH}</value>
</property>
<property>
<name>java.library.path</name>
<value>${LIBRARY_PATH}</value>
</property>
</systemProperties>
...
</plugin>
Related
This is an attempt to create a multi-module JavaFX application with maven.
Given the following structure of the project:
project
| pom1.xml
|_____ Word Generator (Folder)
| pom2.xml
|_____logic (folder)
| WordGenerator
|_____UI (folder)
| pom3.xml
|_____marty
| App
| PrimaryController
| SecondaryController
We have the following structure of the pom files in order of the scheme above:
pom1.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>org.games.marty</groupId>
<artifactId>words</artifactId>
<packaging>pom</packaging>
<version>0.1</version>
<modules>
<module>UI</module>
<module>Word Generator</module>
</modules>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
pom2.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>words</artifactId>
<groupId>org.games.marty</groupId>
<version>0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>word.generator</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.games.marty.logic.WordGenerator</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
pom3.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>UI</artifactId>
<version>0.1</version>
<parent>
<artifactId>words</artifactId>
<groupId>org.games.marty</groupId>
<version>0.1</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>16</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>16</version>
</dependency>
<dependency>
<groupId>org.games.marty</groupId>
<artifactId>word.generator</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>16</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>org.games.marty.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.games.marty.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
The way we have attempted to build the application in order for the UI to have access to the WordGenerator logic is to maven package the result from the pom1.xml directive
We get the above error as mentioned earlier:
Error: Could not find or load main class org.games.marty.App
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
As far as my understanding goes, the JavaFX dependencies are installed throught maven and should be available but they are missing?
Packaging via mvn package using the maven-jar-plugin is not enough
mvn package, by default, is just going to package the jar for your application code, it isn't going to include all of the dependant library code (which is why the dependent code cannot be found when you attempt to run your application).
You could package your application code and dependant libraries using an assembly, as detailed in How can I create an executable JAR with dependencies using Maven?, though that approach is not the only one to solve your problem.
You need to build some kind of runtime image
There are numerous options for building runtime images and I don't know your requirements, so I can't recommend what you should do instead. Example options are:
A zip/tar of your application plus libraries in a separate directory.
The creation of a single jar that includes all dependant code.
Either of solutions 1 or 2, plus the inclusion of a packaged JRE.
A runtime image with your code and libraries which also uses just the custom runtime portions of the JRE and JavaFX modules you need (using jlink).
A native installer for either 3 or 4 (using jpackage + a native installer creation tool, e.g. WIX, RPM, DEB installer creators).
The last method (native installer), is the packaging, distribution, and installation method I would recommend for most non-trivial applications.
You need to research how to do this
To get your solution, you will need to do your own research, and, once you have chosen an approach and toolset, you could create a new question regarding the implementation of that approach, if you continue to have difficulties.
Related resources
How can I create an executable JAR with dependencies using Maven?
openjfx Runtime images documentation
maven shade plugin
Maven Shade JavaFX runtime components are missing
openjfx JavaFX maven plugin
badass runtime plugin
badass jlink plugin
jlink guide
jpackage script
JEP 392: packaging tool
Warning for shaded jars
If you bundle all JavaFX code into a single jar using the maven shade plugin, you will get a warning like the following when you run your application from Java 16+:
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module #28c71909'
This indicates that such a configuration is not supported, and may (and probably will) break in future and perhaps current JavaFX platform revisions. Thus, shaded jars that include JavaFX platform code are not recommended by me, even though such jars might currently work for your deployments.
JavaFX 11+ is built to be used as a set of modules. Configurations are not supported if they do not run the JavaFX platform off of the module path but instead run the platform code off of the classpath (as a shaded jar would).
I'm using IntelliJ IDE with maven. I have a project (main module) with a parent pom, that includes 2 sub modules, each with their own pom.
<!-- main pom module part -->
<packaging>pom</packaging>
<modules>
<module>ModuleA</module>
<module>ModuleB</module>
</modules>
<!-- example for sub module pom -->
<parent>
<artifactId>main-module</artifactId>
<groupId>my.main.module</groupId>
<version>0.5.0</version>
</parent>
Image ModuleA includes the OpenCV Java wrapper and ModuleB is an executable java program (having the main class) using ModuleA.
The compiling works fine, but when I run ModuleB with having set the library path in the launcher, I'll get the following error for ModuleA:
java.lang.NoClassDefFoundError: org/opencv/core/Core
Any suggestions how to fix this?
Ok, I found a solution my self. The problem was, that the opencv java wrapper was included with a system path. Now I use the maven install plugin within the validate live cycle step instead.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>org.opencv</groupId>
<artifactId>opencv</artifactId>
<version>3.3.0</version>
<packaging>jar</packaging>
<file>${project.basedir}/../lib/opencv/opencv-330.jar</file>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Works fine for me, but was not the way I wanted it to be... The system-path type dependency seems to be buggy in maven.
Try to add the following dependency to your ModuleA:
<dependency>
<groupId>nu.pattern</groupId>
<artifactId>opencv</artifactId>
<version>2.4.9-7</version>
</dependency>
I am using the mvn versions:display-dependency-updates versions:display-plugin-updates goals to check for dependencies or plugins updates.
My maven project is a multi module one, which looks like this:
moduleA
|- moduleB1
| |- moduleC
|- moduleB2
|- build-config/rules.xml
Since there is some unwanted updates, like betas I don't want, I've made a filter (which works). I use it like that:
<profile>
<id>maven-version-plugin-1</id>
<activation>
<property>
<name>version.rules.uri</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<configuration>
<rulesUri>${version.rules.uri}</rulesUri>
</configuration>
</plugin>
</plugins>
</build>
</profile>
I am forced to use a profile and a property version.rules.uri because it must refer to an existing file (by default it points to ./build-config/rules.xml, but it is also in my settings.xml with an absolute path).
I'd like to avoid that by:
publishing an independent build-config project
referencing this project using some uri: m2:myGroupId:myArtifactId:version:scope:jar/rules.xml
Now the question: is there an implementation of Maven Wagon Plugin (which is used by maven versions plugin) that allow for reading a repository entry such as a jar ?
This works for me:
<rulesUri>file:///${session.executionRootDirectory}/maven-version-rules.xml</rulesUri>
For the meaning of the variable ${session.executionRootDirectory}, see
Finding the root directory of a multi module maven reactor project.
Based upon the documentation for the plugin this is possible:
You can provide your ruleset xml file also within a jar, if you want to distribute your ruleset xml as Maven artifact. Therefore you have to declare the containing jar as direct dependency of the versions-maven-plugin and to use classpath as protocol.
I just tried it out and got it to work.
Create a new folder for the new version-rules artifact, as so:
version-rules
|- files
\- version-rules.xml
\- pom.xml
The pom.xml is pretty basic:
...
<artifactId>my-version-rules</artifactId>
<packaging>jar</packaging>
<build>
<defaultGoal>package</defaultGoal>
<resources>
<resource>
<directory>files</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
...
run a mvn install to install this artifact.
Then, in the other pom, you configure the versions plugin as follows:
...
<build>
...
<pluginManagement>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<rulesUri>classpath:///version-rules.xml</rulesUri>
</configuration>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>my-version-rules</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
...
</pluginManagement>
...
</build>
...
I just started a new Maven project that is intended to start a Jetty containing a war-File from a depended project. The cargo-plugin should be the right tool for this.
Unfortunately it doesn't work for me. It starts Jetty successfully but it only contains the default-cargo-war-file, not the expected one.
This is the relevant part of my war-File:
<dependencies>
<dependency>
<groupId>com.group</groupId>
<artifactId>my-webapp</artifactId>
<version>0.1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.5</version>
<configuration>
<container>
<containerId>jetty7x</containerId>
<type>embedded</type>
</container>
<configuration>
<properties>
<cargo.servlet.port>7070</cargo.servlet.port>
<cargo.logging>high</cargo.logging>
</properties>
</configuration>
<deployer>
<type>embedded</type>
<deployables>
<deployable>
<groupId>com.group</groupId>
<type>war</type>
<artifactId>my-webapp</artifactId>
<properties>
<context>/path</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
</plugin>
</plugins>
</build>
I use the plugin by starting mvn cargo:start.
There is no error log output.
[INFO] [cargo:start]
[INFO] [beddedLocalContainer] Jetty 7.x Embedded starting...
2011-01-17 18:57:44.586:INFO::jetty-7.2.0.v20101020
2011-01-17 18:57:44.663:INFO::Extract jar:file:/tmp/cargo/conf/cargocpc.war!/ to /tmp/jetty-0.0.0.0-7070-cargocpc.war-_cargocpc-any-/webapp
2011-01-17 18:57:45.082:INFO::Started SelectChannelConnector#0.0.0.0:7070
[INFO] [beddedLocalContainer] Jetty 7.x Embedded started on port [7070]
How can I tell Cargo to load the specified war-File?
Ok, I got it to work now.
As it seems, cargo silently ignores any snapshot dependencies. So you have to release a project before using it in a cargo-project.
Probably this is a bug. I can't imagine any sensible reason for this behaviour.
(also the pom-File I posted above was not correct, you have to adapt the changes that Robin suggests in his answer)
Try this. Set your configuration type to standalone and put the deployables in the configuration. Make sure the correct project dependency exists to resolve the war.
<configuration>
<type>standalone</type>
<properties>
<cargo.servlet.port>7070</cargo.servlet.port>
<cargo.logging>high</cargo.logging>
</properties>
<deployables>
<deployable>
<groupId>com.group</groupId>
<type>war</type>
<artifactId>my-webapp</artifactId>
<properties>
<context>/path</context>
</properties>
</deployable>
</deployables>
</configuration>
Its seems it could work better if you first do the deployment say run a command "mvn cargo:deploy" then run a "mvn cargo:start"
If you just want to deploy on embedded Jetty, you may not need Cargo. Just use this, in your web-app's pom.xml:
<build>
...
...
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.2.2.v20101205</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppConfig>
<contextPath>/path</contextPath>
</webAppConfig>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>7070</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
...
...
</plugins>
...
...
</build>
to build and start Jetty user
mvn clean install jetty:run
I've created a test which extends GWTTestCase but I'm getting this error:
mvn integration-test gwt:test
...
Running com.myproject.test.ui.GwtTestMyFirstTestCase
Translatable source found in...
[WARN] No source path entries; expect subsequent failures
[ERROR] Unable to find type 'java.lang.Object'
[ERROR] Hint: Check that your module inherits 'com.google.gwt.core.Core' either directly or indirectly (most often by inheriting module 'com.google.gwt.user.User')
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.1 sec <<< FAILURE!
GwtTestMyFirstTestCase.java is in /src/test/java, while the GWT module is located in src/main/java. I assume this shouldn't be a problem.
I've done everything required according to http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html and of course that my gwt module already has com.google.gwt.core.Core indirectly imported.
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>main</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Main Module</name>
<properties>
<gwt.module>com.myproject.MainModule</gwt.module>
</properties>
<parent>
<groupId>com.myproject</groupId>
<artifactId>app</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>app-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${gwt.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputFile>../app/src/main/webapp/WEB-INF/main.tree</outputFile>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>
${project.build.directory}/${project.build.finalName}/${gwt.module}
</classesDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here is the test case, located in /src/test/java/com/myproject/test/ui
public class GwtTestMyFirstTestCase extends GWTTestCase {
#Override
public String getModuleName() {
return "com.myproject.MainModule";
}
public void testSomething() {
}
}
Here is the gwt module I'm trying to test, located in src/main/java/com/myproject/MainModule.gwt.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.1/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name='com.myproject.Commons' />
<source path="site" />
<source path="com.myproject.test.ui" />
<set-property name="gwt.suppressNonStaticFinalFieldWarnings" value="true" />
<entry-point class='com.myproject.site.SiteModuleEntry' />
</module>
Can anyone give me a hint or two about what I'm doing wrong?
To reproduce the solution used by KevinWong from the maven-gwt-plugin doc, which worked for me after losing over an hour trying the other solutions.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
<additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
</additionalClasspathElements>
<useManifestOnlyJar>false</useManifestOnlyJar>
<forkMode>always</forkMode>
<systemProperties>
<property>
<name>gwt.args</name>
<value>-out \${webAppDirectory}</value>
</property>
</systemProperties>
</configuration>
</plugin>
I don't think the right thing to do is just to exclude the tests from your maven life cycle. What's the point of writen them? What you have to do is to properly configure the maven-surefire-plugin in order to make it work.
You see, that plugin uses a system classloader to look up the classes but GWTTestCase needs an URLClassLoader. That's the reason you are getting [WARN] No source path entries; expect subsequent failures. and the following ClassNotFoundException. No worries, though. It's easy to tell maven to use a URLClassLoader instead:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/src/main/java</additionalClasspathElement>
<additionalClasspathElement>${basedir}/src/test/java</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
Please, notice the <userSystemClassLoader>false</useSystemClassLoader> entry.
Also, notice that I added the sources of my tests and main directories in order to allow GWT find the needed classes to generate the Javascript. You might need to configure it differently.
The problem was that the test was run by surefire instead of gwt-maven plugin. I had to explicitly exclude my gwt tests from surefire plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*GwtTest*.java</exclude>
<exclude>**/*Gwt*Suite*.java</exclude>
</excludes>
</configuration>
</plugin>
I still can't run my GWTTestCase tests, but that's another problem and subject for another question. I consider this issue solved.
First exclude gwt testcases from maven-surefire-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<excludes>
<exclude>**/*GwtTest.java</exclude>
</excludes>
</configuration>
</plugin>
Then configure gwt-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>**/*GwtTest.java</includes>
<mode>htmlunit</mode>
</configuration>
</plugin>
Now you can easily run gwt testcases using gwt:test.
I am very confident that this error has nothing to do with maven setup. My first guess would be that tests are not on gwt compile path... I guess the problematic source code is:
<source path="com.myproject.test.ui" />
try changing to:
<source path="com/myproject/test/ui" />
or whatever is the appropriate path.
the solution to this
"[ERROR] Unable to find type 'java.lang.Object'
[ant:java] [ERROR] Hint: Check that your module inherits 'com.google.gwt.core.Core'
either directly or indirectly (most often by inheriting module 'com.google.gwt.user.User')"
GWT compilation error is to use "fork='true'" when invoking GWT compiler.
that's why the solutions posted here magically worked - they have "forkMode=always" and similar.
here's how I call GWT compiler:
ant.java(classname: 'com.google.gwt.dev.Compiler', failOnError: 'yes', maxmemory: '1000m', fork: 'true')
and here's the full GWT compiler call in Gradle:
war {
// Exclude unneccessery GWT Compiler artifacts
exclude "**/gwt-unitCache/**"
}
task widgetset << {
// Create widgetset directory (if needed)
def created = (new File(gwtBuildDir)).mkdirs()
// Compile
ant.java(classname: 'com.google.gwt.dev.Compiler', failOnError: 'yes', maxmemory: '1000m', fork: 'true')
{
classpath {
pathElement(path: configurations.compile.asPath)
pathElement(path: sourceSets.main.runtimeClasspath.asPath)
sourceSets.main.java.srcDirs.each {
pathelement(location: it.absolutePath)
}
}
arg(line: '-war ' + gwtBuildDir)
arg(line: '-logLevel INFO')
arg(line: '-style OBF')
arg(line: '-localWorkers 2')
arg(line: widgetsetClass)
// jvmarg(value: '-Djava.awt.headless=true')
// jvmarg(value: '-XX:MaxPermSize=256M')
// jvmarg(value: '-Xmx500M')
}
}
// Require widgetset compilation before WAR is built
war.dependsOn widgetset
This sunfire config worked for me.