How to Package a Mixed Java‑Groovy Maven Project in IntelliJ
This guide explains how to transition from Gradle to Maven for a Java‑Groovy mixed project, covering folder renaming, essential Maven dependencies and plugins, manifest configuration, and a note on optional local‑jar settings to successfully build an executable JAR in IntelliJ.
Adjust project layout for mixed Java‑Groovy sources
Rename the original src/main/java directory to src/main/groovy. Maven will then treat the source tree as Groovy, allowing both Java and Groovy files to be compiled together.
POM dependencies
Add the Groovy runtime library that matches the Groovy version used in the project.
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.8</version>
</dependency>Build configuration
Three Maven plugins are required:
maven-compiler-plugin – compiles Java sources with Java 1.8 compatibility.
maven-jar-plugin – builds the executable JAR, adds a manifest with Class-Path and the main class.
gmaven-plugin – compiles Groovy sources, generates stubs, and integrates Groovy into the Maven lifecycle.
The complete <build> section looks like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.okayqa.studentapd.T2</mainClass>
</manifest>
<manifestEntries>
<Class-Path>/Users/fv/Documents/workspace/fun/build/libs/fun-1.0.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.2</version>
<configuration>
<providerSelection>1.7</providerSelection>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-1.7</artifactId>
<version>1.2</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>1.7.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>Important notes
The manifestEntries block adds a local JAR to the manifest. If the path appears red in the IDE but points to an existing file, the build will still succeed.
All plugin versions shown are known to work together; adjust them only if you need newer features.
After applying the directory rename and the pom.xml changes, run mvn clean package. Maven will compile both Java and Groovy sources, generate the executable JAR, and place any dependent libraries under target/lib as specified by the manifest.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
