Maven GWT plugin adding other source directories - gwt

How do I add another source directory to the maven gwt compile plugin? I have some generated code that I need to include in the compile.
If I can't, what do people suggest to get around this?

I don't know if you have looked into this, but you could use the compileSourcesArtifacts attribute to include your generated code as an external library. There is an article on setting this up in the GWT Plugin Documentation. However, this will only work if you don't need the external code to be included with your web app.
Whenever we needed to do this in the past, we used the maven-resources-plugin's copy-resources goal to copy the source code into our main package structure, and configured the maven-clean-plugin to remove the files. Because the gwt compile happens during the prepare-package phase of the build lifecycle, you would need to copy your source files into the directory before that (we bound ours to process-classes).

I put the i18n goal at the generate-resourcces phase and it worked well. It will be executed before the gwt compile.
<plugins>
<!-- GWT Maven Plugin-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.0-rc1</version>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${gwtVersion}</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
</dependency>
</dependencies>
<executions>
**<execution>
<id>generate-i18n</id>
<phase>generate-resources</phase>
<goals>
<goal>i18n</goal>
</goals>
</execution>**
<execution>
<phase>prepare-package</phase>
<goals>
<goal>resources</goal>
<goal>compile</goal>
<goal>test</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- your config -->
</configuration>
</plugin>

This works because your generated output is generated in the normal source folder.
But the question was how to add an extra source folder.

Related

JPA Static Metamodel not recognized by IntelliJ

I generated the application with JHipster with Gradle as the build tool.
When I created entity I added filtering support, which generated JPA static metamodel. But IntelliJ doesn't recognize the metamodels.
I have enabled the annotation processor settings on IntelliJ but it doesn't seem to work.
What settings do I have to change for IntelliJ to recognize the JPA static metamodels?
By default, the metamodel classes get generated into the /target/generated-sources/annotations folder. It seems like that folder isn't registered as a source folder.
You can either change that manually in your IDE or if you're using a Maven build, you can do that automatically by adding the following plugin to your build configuration:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/annotations</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
I explained that in more details in one of my Hibernate Tips.
I'm not allowed to comment but I wanted to add to Thorben Janssen's answer.
Besides the plugin config I also had to add this to the dependencies of the project:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.21.Final</version>
</dependency>
This is what generates the sources in the target/generated-sources/annotations path.
So the pom ended up like this:
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.21.Final</version>
</dependency>
...
</dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-source</id>
<goals>
<goal>add-source</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<sources>
<source>target/generated-sources/annotations</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
To get IntelliJ IDEA to recognize the generated classes, I had to add this line on build.gradle
sourceSets {
main.java.srcDirs += 'build/generated/source/apt/main'
}
Update
Better solution is to modify IntelliJ Plugin
idea {
module {
sourceDirs += file("build/generated/source/apt/main")
generatedSourceDirs += file("build/generated/source/apt/main")
}
}
Intellij's build recognize all processors listed in this file:
META-INF/services/javax.annotation.processing.Processor
.
Case you use Eclipse Link, include this line inside the file:
org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
Case Hibernate:
org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
Ensure that you have all dependencys: I will describe using maven just for example:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.7.0</version>
<scope>provided</scope>
</dependency>
OR
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.2.12.Final</version>
<scope>provided</scope>
</dependency>
For me it wasn't a problem of the configuration files (none of the above mentioned solutions worked), but I simply had to reload all Maven project files.
For this in IntelliJ Idea:
Go to the Maven tab on the right side of the IDE (you might have to make it visible under View -> Tool Windows)
Open the project and compile
On the top left corner of the tab press Reload all Maven Projects
Now, the meta classes (e.g. SampleClass_) should be importable and recognized by IntelliJ

gwt-maven-plugin how to add the source jar in another module pom.xml

my application has 2 module, one is jar and the other is gwt war. in the jar module (non-gwt) pom.xml, I add
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
and als-admin-viewer-core-1.0.0-sources.jar is successfully created.
Then In the webapp(a gwt application) pom.xml, I want to use this jar, and in the segment, I add
<plugin>
<groupId>org.codehaus.mojo<groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
<dependencies>
<dependency>
<groupId>hk.gov.ehr.service.tch.als</groupId>
<artifactId>als-admin-viewer-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>hk.gov.ehr.service.tch.als</groupId>
<artifactId>als-admin-viewer-core</artifactId>
<version>1.0.0</version>
<classifier>sources</classifier>
</dependency>
</dependencies>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
</executions>
........
but when I run maven install for this project (als-admin-viewer-webapp), error
No source code is available for type hk.gov.ehr.service.tch.als.admin.viewer.core.LogSearchCriteria; did you forget to inherit a required module?
is prompted.
what is the problem?!!
I even try to add
<compileSourcesArtifacts>
<compileSourcesArtifact>hk.gov.ehr.service.tch.als:als-admin-viewer-core</compileSourcesArtifact> <!-- groupId:artifactId -->
</compileSourcesArtifacts>
in
<configuration>
section of gwt-maven-plugin, but it still does not help!!
I think you forgot to create "gwt.xml" file in your jar module and inherit it in your main gwt.xml (inside gwt maven module).
Please look at
http://mojo.codehaus.org/gwt-maven-plugin/user-guide/library.html
for details (section "Using general purpose JARs as GWT library").
Also bear in mind: if you're using maven-source-plugin to attach sources, your sources will be distributed with the web application. And if you're using "compileSourcesArtifacts" you avoid this side-effect.

How to compile a widgetSet in vaadin?

I am trying to use the visualizationsForVaadin add-on. The problem is, that I have to compile a custom widgetSet. I've been dealing with this the whole day, and still cannot compile it. First of all, here is my configuration:
Vaadin 6.7.1
gwt 2.3.0
following dependencies are in my pom file:
gwt-ajaxloader 1.1.0
validation-api 1.0.0.GA
gwt-visualization 1.0.2
gwt-user 2.3.0
visualizationsforvaadin 1.1.2.
When I try to compile the widgetSet with maven gwt plugin I get an exception:
Loading inherited module 'com.google.gwt.core.XSLinker'
[ERROR] Line 22: Unexpected element 'when-linker-added'
[ERROR] Failure while parsing XML
An interesting thing is, that the gwt-dev library, that is automatically loaded (as far as I know) is of version 2.0.3
I have tried everything possible (even impossible) and still nothing. At some point I had other exceptions complaining that the import of validation classes could not be resolved. I think, that has been resolved by some other dependencies. Please help. Thank you.
POM configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<!-- Version 2.1.0-1 works at least with Vaadin 6.5 -->
<version>2.3.0</version>
<configuration>
<!-- if you don't specify any modules, the plugin will find them -->
<!--modules>
..
</modules-->
<webappDirectory>${project.build.directory}/${project.build.finalName}/VAADIN/widgetsets</webappDirectory>
<extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
<runTarget>clean</runTarget>
<hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
<noServer>true</noServer>
<port>8080</port>
<soyc>false</soyc>
</configuration>
<executions>
<execution>
<goals>
<goal>resources</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
</dependency>
</dependencies>
</plugin>
And here are the GWT dependencies
<dependency>
<groupId>com.google.gwt.google-apis</groupId>
<artifactId>gwt-visualization</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>com.google.gwt.google-apis</groupId>
<artifactId>gwt-ajaxloader</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.vaadin.addons</groupId>
<artifactId>visualizationsforvaadin</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin</artifactId>
<version>${vaadin.version}</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
</dependency>
I struggled with this over the past 2 days.
For future reference:
What you'll need:
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiler</artifactId>
<version>${versions.vaadin}</version>
</dependency>
Configure gwt-maven-plugin as follows (you may not need all configs that I used, of course):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${versions.gwt}</version>
<configuration>
<extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
<webappDirectory>${basedir}/src/main/webapp/VAADIN/widgetsets
</webappDirectory>
<hostedWebapp>${basedir}/src/main/webapp/VAADIN/widgetsets
</hostedWebapp>
<noServer>true</noServer>
<draftCompile>true</draftCompile>
<compileReport>false</compileReport>
<style>DETAILED</style>
<runTarget>http://localhost:8080/</runTarget>
</configuration>
<executions>
<execution>
<goals>
<goal>resources</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
The vaadin-maven-plugin:
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${versions.vaadin}</version>
<executions>
<execution>
<configuration>
<!--<modules>
<module>org.vaadin.aceeditor.AceEditorWidgetSet</module>
</modules>-->
</configuration>
<goals>
<goal>update-widgetset</goal>
</goals>
</execution>
</executions>
</plugin>
You may also want to configure your maven-clean-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>
${basedir}/src/main/webapp/VAADIN/widgetsets
</directory>
</fileset>
</filesets>
</configuration>
</plugin>
In web.xml for your servlet (Ace Editor as an example):
<init-param>
<param-name>widgetset</param-name>
<param-value>org.vaadin.aceeditor.AceEditorWidgetSet</param-value>
</init-param>
Note that I did NOT include gwt as a dependency in my pom.xml.
I have a fully functional Vaadin project with custom widgets in Eclipse and I can't find any references to gwt-dev anywhere in the project. Go to Project properties -> Java Build Path -> Libraries and delete all references to gwt-dev. Also remove it from your pom.xml and try to recompile the widgetset.
edit: It could also be your gwt-user dependency. Try setting the version of gwt-user to 2.3.0 (if it already isn't) and set the scope to provided.

Maven GWT Plugin copies multiple versions of the same snapshot jars

I have this issue where I build my project (mvn clean install), some of the transitive dependencies are snapshot versions and are downloaded and copied into the target webapp directory e.g XXXUtil-1.0-20110922.172721-52.jar. Then when I run mvn gwt:run, it finds uses XXXUtil-1.0-SNAPSHOT.jar and copies it to the target webapp directory. I can't figure out why this is happening. In doesn't matter whether I run as exploded or inplace.
<plugins>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.3.0-1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>Shell.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundle>com.myapp.client.Messages</i18nMessagesBundle>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${gwt.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- Copy static web files before executing gwt:run -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- <outputFileNameMapping>#{artifactId}#-#{version}#.#{extension}#</outputFileNameMapping> -->
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
</plugins>
None of the suggestions described here help:
http://www.tikalk.com/alm/forums/maven-war-plugin-picking-multiple-version-same-snapshot-jars.
If i build local snapshots of XXXUtil-1.0-SNAPSHOT.jar it works buts not when downloading snapshots from a nexus repository. Another way to look at it is like this Project A generates a WAR, and depends on B.jar, which depends on C.jar. When i build my war using mvn install, it generates the correct jars in WEB-INF/lib so we have C-1.0-20110922.172721-52.jar. Which is correct and it works if i deploy my war. If i run in hosted mode using eclipse, its fine. But when i run mvn:gwt-run, C-1.0-SNAPSHOT.jar is copied into WEB-INF/lib so i have 2 jars C-1.0-SNAPSHOT.jar and C-1.0-20110922.172721-52.jar.
The only thing I can suggest you is to try to debug maven-gwt-plugin.
Checkout it from git repository
https://github.com/gwt-maven-plugin/gwt-maven-plugin.git
I had exactly the same problem. After debugging, I removed the use of maven-war-plugin and added maven-resources-plugin (compile phase, copy-resources goal). I tried gwt:run and install after that, worked without any problems. This way, we avoid the dependencies getting copied twice.

Getting groovy, maven, and eclipse to play nice together?

So we have some unit tests written in groovy. We have the Groovy Eclipse plugin going, we have gmaven going, but the problem is that the maven eclipse plugin doesn't automatically add the src/test/groovy directory as a source directory. So, I enlisted the build-helper plugin to add a source directory, but then the problem becomes the source directory - in eclipse, the filters will include **/*.java and exclude everything else, which leads to the groovy eclipse plugin being confused. I've managed to jury-rig the problem by using the build helper to add-test-resource with the right .groovy file filter. Obviously the problem here is that is not usable if we decided to use groovy classes in the projects - the .groovy classes would be included in the .jar files.
How do I fix this?
I dumped gmaven in favor of the groovy-compiler-plugin, which does the groovy compiler weaving for you. With gmaven I wound up with too many weird compiler errors where stubs were missing, etc. You still need the builder-helper, and the Groovy Eclipse plugin helps in linking the source to the compiled classes, but this has worked flawlessly between working within eclipse and at the command line.
<properties>
<groovy.version>1.8.0</groovy.version>
<groovy.provider>1.7</groovy.provider>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/groovy</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/groovy</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
<source>1.6</source>
<target>1.6</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>1.8.0-03</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.5.1</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
We have created m2eclipse integration for Groovy-Eclipse. First, you must install m2eclipse:
http://m2eclipse.sonatype.org/sites/m2e
Then you can install the Groovy-Eclipse integration, which you can get here:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.6/
or here for Galileo:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.5/
Note that the m2eclipse integration is still beta and we appreciate feedback from users to see how well it works for them.
I happened to check out the maven eclipse plugin page and it turns out this type of problem is already solved:
http://maven.apache.org/plugins/maven-eclipse-plugin/examples/specifying-source-path-inclusions-and-exclusions.html
I ended up just using the build-helper-plugin to specify additional sources and added .groovy files to the source includes for the eclipse plugin.