Groovy Eclipse compiler plugin for maven does not compile anything

I am trying to understand the correct configuration of Java and the Groovy project in Maven by compiling the source files using groovy -eclipse-compiler.

According to the plugin , if you have files in src/main/java and src/test/java , the compiler should find both Java and Groovy by default.

The build setting, as in the example, makes target/classes empty.

 <build> ... <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <compilerId>groovy-eclipse-compiler</compilerId> <!-- set verbose to be true if you want lots of uninteresting messages --> <!-- <verbose>true</verbose> --> </configuration> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>2.7.0-01</version> </dependency> </dependencies> </plugin> ... </plugins> </build> 

The only way I worked with is to use build-helper-maven-plugin . This is an option that is also used in Archetype:

 mvn archetype:generate \ -DarchetypeGroupId=org.codehaus.groovy \ -DarchetypeArtifactId=groovy-eclipse-quickstart \ -DarchetypeVersion=2.5.2-SNAPSHOT \ -DgroupId=foo \ -DartifactId=bar \ -Dversion=1 \ -DinteractiveMode=false \ -DarchetypeRepository=https://nexus.codehaus.org/content/repositories/snapshots/ 

So is this page out of date? Are there few Java files in the src folder?

+4
source share
1 answer

I can make it work. Here is what I did:

  • create an archetype as you did above.
  • edit the pom.xml file in the file below
  • mv everything from src / main / groovy to src / main / java and the same for tests.
  • remove empty groovy dirs
  • rename all * .java files to * .groovy
  • mvn clean compile
  • I get some expected compilation errors due to differences in Java vs groovy syntax, but all groovy files are recognized.

Does this work for you? If not something else?

Here is the pom file I'm using:

 <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>foo</groupId> <artifactId>bar</artifactId> <version>1</version> <name>bar Groovy Eclipse Maven Java App</name> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <compilerId>groovy-eclipse-compiler</compilerId> </configuration> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>2.7.0-01</version> <exclusions> <exclusion> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-batch</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-batch</artifactId> <version>2.1.1-01</version> </dependency> </dependencies> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>2.1.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> </dependencies> </project> 

EDIT

Since I misunderstood the actual question, and you want to save the files separately, then there are 2 options:

  • using the build-helper plugin as you did
  • Use groovy -eclipse-compiler mojo:

  <plugin> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>2.7.0-01</version> <extensions>true</extensions> </plugin> </build> 

All of this is described on the groovy -eclipse-compiler page.

+6
source

Source: https://habr.com/ru/post/1479595/


All Articles