I am trying to run Spock tests and perhaps some Groovy scripts, currently for a Groovy app, but in future for Java projects as well.
I am really confused about which plugins should be used and how to best configure them, aka least amount of code.
I found numerous articles showing Maven XML settings for gmaven-plugin, gmaven-runtime and groovy-eclipse plugin, which seems like it works under IDEA as well.
I have been using Eclipse for a while and now am trying out IDEA Community Edition.
One of the confusions stems from the fact that I was able to add following dependency to my POM, in addition to having Gmaven in section.
<dependency>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
</dependency>
I understand that the question is a bit vague... but so is documentation on the matter :)
For fully Maven-Groovy projects read this post Building your Groovy 2.0 projects with Maven
I have sample project with Maven, Java and Spock tests. There is one requirement here. Spock tests needs to have names like FooTest.groovy.
My configuration looks like this
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<configuration>
<providerSelection>2.0</providerSelection>
<source/>
</configuration>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-2.0</artifactId>
<version>1.5</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
</plugin>
Fully working project is here: https://github.com/mariuszs/java-spock-test-sample
Related
I am trying to get started with OSGI and create a basic bundle.
I created a bundle with activator in Eclipse (2019-06) and selected Liberty as the target runtime (the end goal is to create a Liberty extension)
It works fine, but when I convert it to Maven, Eclipse complains the org.osgi package cannot be resolved
I see this dependency is defined:
<dependency>
<groupId>net.wasdev.maven.tools.targets</groupId>
<artifactId>liberty-target</artifactId>
<version>19.0.0.9</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
I tried adding this to the felix plugin with no luck.
<Import-Package>
org.osgi.framework
</Import-Package>
After trying thing for a while I am ready to give up. Any help would be appreciated.
Add these maven dependencies for the OSGi specs.
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
You also have to configure the bnd-maven-plugin. So your imports are computed automatically. Alternatively you can use the maven-bundle-plugin. (You might already use this).
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>4.2.0</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
This covers the compile time resolution of your packages.
In addition you need to provide the correct bundles at runtime. This highly depends on how you define your runtime.
Some org.osgi package come from the OSGi framework itself. Others have to be installed as bundles. Be aware that you normally do not install the specs as bundles. Instead you install implementations that also bring the specs.
My entire pom.xml is below. With this pom I get this error in Eclipse "Plugin execution not covered by lifecycle configuration: org.apache.cxf:cxf-java2ws-plugin:3.1.8:java2ws (execution: process-classes, phase: process-classes)".
Nevertheless, it does work properly. I mean, if I "mvn clean package install" I get the output wsdl file desired.
If I added pluginManagement, the error in Eclipse desapears but I don't get the wsdl file desired neither I get an error in my console. The two closest discussions I found about it was "Publishing wsdl java M2E plugin execution not covered" and "How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds" but I didn't understand them. As far as I can see, the idea is to change to take advantage of
"<lifecycleMappingMetadata>...<action><execute/>".
My straight question is: why does my below pom works when I take away pluginManagement? I guess, not sure, that I am missing a basic knowledgement about the relantionship between pluginManagement and execution. The most relevant part from my question is not what is worng with Eclipse (I found few people saying to ignore it).
I have been using pluginManagement for while but I have never wondering exactly what extra features it adds to my pom. Since now it is failing with java2ws, I am really interested to understand if there is any extra configuration I should add in my pom in order to get it up and running with pluginManagement and goal>java2ws.
<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>grp</groupId>
<artifactId>art</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>art Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<jdk.version>1.8</jdk.version>
<cxf.version>3.1.8</cxf.version>
<spring.version>4.3.4.RELEASE</spring.version>
<!-- <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> -->
</properties>
<dependencies>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Apache cxf dependencies -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- servlet & jsp -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
<finalName>art</finalName>
<!-- <pluginManagement> -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<configuration>
<className>art.VmxService</className>
<outputFile>${project.basedir}/src/main/resources/VmxService.wsdl</outputFile>
<genWsdl>true</genWsdl>
<verbose>true</verbose>
<address>http://localhost:9080/art/VmxService</address>
</configuration>
<goals>
<goal>java2ws</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!-- </pluginManagement> -->
</build>
</project>
The pluginManagement section serves a similar purpose like the dependencyManagement section. It defines plugins and their version and configuration defaults, without actually adding them to the maven build lifecycle.
Once the plugin is added in a module it will pick up the configuration from the pluginManagement section.
Also see: Maven: What is pluginManagement?
So if a similar configuration of the same plugin is used in multiple modules you can collect them together in one place. If the plugin is only used in one module I prefer to just put it in there directly in the build. But both ways work.
Remember you also need to add the plugin to the build.plugins - simply having them in pluginManagement does nothing.
The warning in eclipse relates more to the life-cycle of your IDE. It differs a bit from the maven lifecycle and in some cases it cannot detect (or could not?) at what moment a plugin is supposed to run. Some plugins also cannot execute without a maven project. So I'm never sure what that lifecycle-mapping plugin tries to solve :/
Anyways: if you generate the classes using a maven build and this works for you (not having that done when telling eclipse to 'build' the project without maven) you're good.
I thought that information (the lifecycle mapping) is nowadays baked into the plugins directly and read by the m2eclipse plugin. I've seen such xml files in some plugins. So the lifecycle-mapping plugin might not be required anymore at all.
When I try to create Maven project with this parameters:
Archetype Group Id - org.codehaus.mojo;
Archetype Artifact Id - gwt-maven-plugin;
Archetype Version - 2.3.0-1.
I get some strange errors:
Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:gwt-maven-plugin:2.3.0-1:generateAsync (execution: default, phase: generate-sources)
Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:gwt-maven-plugin:2.3.0-1:i18n (execution: default, phase: generate-sources)
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-war-plugin:2.1.1:exploded (execution: default, phase: compile)
And some warnings as:
Implementation of project facet jst.web could not be found. Functionality will be limited.
Implementation of project facet wst.jsdt.web could not be found. Functionality will be limited.
This is my pom.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/maven-v4_0_0.xsd">
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>net.test1</groupId>
<artifactId>TestWebApp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>GWT Maven Archetype</name>
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.3.0</gwtVersion>
<!-- GWT needs at least java 1.5 -->
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<classifier>sources</classifier>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<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>test</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see
gwt-maven-plugin documentation at codehaus.org -->
<configuration>
<runTarget>TestWebApp.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundle>net.test1.TestWebApp.client.Messages</i18nMessagesBundle>
</configuration>
</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>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
And so on. What is this? I have tried all possible manuals on the Internet, and everywhere the same. I tried to create project manualy without eclipse and the same. I think, the problem is that manuals in the Internet was writing for old version of Eclipse, Maven, GWT. How can I beat it? How can I just create simple project with GWT 2.3, Maven2 plugin and Eclipse Indigo without errors end warnings?
This is known behavior, discussed on the eclipse wiki. See here: http://wiki.eclipse.org/M2E_plugin_execution_not_covered.
Don't just comment out the problematic sections of your pom, you really do need them. For instance The generated comment for that maven-war-plugin in the pom is "Copy static web files before executing gwt:run" This turns out to be true. If you comment out that plugin and "mvn clean gwt:run", static files will not be copied to the target folder and be unavailable to hosted mode.
Fortunately the workaround is easy. If you open up the pom in Eclipse, look in the Overview section, and click the error message at the top, it will give you some quick fix options. Such as "Permanently mark goal exploded in pom.xml as ignored." This will add some m2e configuration to your pom so it is no longer flagged as an error, and everything will work as before. The newly generated section in your pom is what is described in the link above as the "ignore" option.
Hope this helps.
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.
I have been maintaining a maven java project for year.
Recently, I learned Ruby and asked why haven't these nice features (of Ruby) existed in Java, and I am so happy to find Groovy the answer. It's already out there for more than 6 years and what a shame I didn't know about it sooner.
Now come to the story:
I have a lot of java code written already, organized in folder structures follow maven default convention (src/main/java for logic & src/test/java for test)
Now, I want to write some new stuff in Groovy, so I guess I should create src/main/groovy for groovy logic and src/test/groovy for test. However, both mvn eclipse:eclipse and the latest m2eclipse only understand and include src/main/groovy as source code folder of the generated eclipse project, and don't not recognize src/test/groovy at all.
Is this the correct behavior? Or am I missed any thing?
By the way, here is the gmaven plugin configured inside my POM:
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<providerSelection>1.7</providerSelection>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-1.7</artifactId>
<version>1.2</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>groovy-all</artifactId>
<groupId>org.codehaus.groovy</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.7.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<configuration>
<providerSelection>1.7</providerSelection>
</configuration>
</plugin>
...
</plugins>
...
</build>
You may find that you have better luck with new version of m2eclipse instead of eclipse:eclipse. Either way, once your project is in eclipse, navigate your src/{main,test}/ folder, right-click and choose Build Path and "User as Source Folder".
Using eclipse can be more comfortable :
Import your project into eclipse as "Maven project"
1) go to Eclipse Marketplace & install groovy compiler
2)right-click on project and configure it as groovy project
3)result :