Groovy + Java 混合编程方案:GMaven

2年前 (2022) 程序员胖胖胖虎阿
231 0 0

Groovy + Java 混合编程方案:GMaven

Hava a look

先看效果。在项目中随便创建一个 SayHiUtil.groovy,然后在main里面添加个执行打印一下

package com.cmb.lr20.zxb.dialog.utils

class SayHIUtil {

    static def sayHi() {
        println "Hi groovy"
    }
}
public class DialogApplication {

    public static void main(String[] args) {
        SayHIUtil.sayHi();
        SpringApplication.run(DialogApplication.class, args);
    }
}

Groovy + Java 混合编程方案:GMaven

DO IT!

使用GMavenPlus,只需加个 plugin 和 dependency 即可:

    

    <dependencies>
        <!-- Groovy -->
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy</artifactId>
            <version>3.0.9</version>
        </dependency>
    </dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <version>1.13.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>addSources</goal>
                        <goal>addTestSources</goal>
                        <goal>generateStubs</goal>
                        <goal>compile</goal>
                        <goal>generateTestStubs</goal>
                        <goal>compileTests</goal>
                        <goal>removeStubs</goal>
                        <goal>removeTestStubs</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <!-- if including source jars, use the no-fork goals
                     otherwise both the Groovy sources and Java stub sources
                     will get included in your jar -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <!-- source plugin \> = 2.1 is required to use the no-fork goals -->
            <version>3.2.1</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar-no-fork</goal>
                        <goal>test-jar-no-fork</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
版权声明:程序员胖胖胖虎阿 发表于 2022年11月1日 下午12:00。
转载请注明:Groovy + Java 混合编程方案:GMaven | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...