由于自己之前使用的是Gradle建構工具,最近切到Maven有些不太适應,特别是在java和groovy混編時,在打包jar包的過程中出現問題,困擾了很久,在網上查了一些資料,都是引入build插件即可,但是插件有的是eclipse的插件,進過分析和摸索終于得到了一個再intellij使用Maven打包混編項目的jar包的方法。
首先把項目的java檔案夾改成groovy,如圖:

然後就是配置pom檔案,分依賴和build兩部分:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.8</version>
</dependency>
<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> <!-- 運作jar的main class -->
</manifest>
<!-- 添加本地的jar -->
<manifestEntries>
<!-- 這個>lib/class-util-1.0.jar 路徑是已經被打包到target/lib裡的,多個包用空格隔開就可以了 -->
<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>
readme.markdown · 八音弦/tester - 碼雲 Gitee.comgitee.com