天增的博客
首页
博客
  • 分布式解决方案
  • Java并发工具包
  • redis
  • LeetCode
  • 系统设计
  • JVM体系
Github (opens new window)
Rss (opens new window)
  • zh-CN
  • en-US
首页
博客
  • 分布式解决方案
  • Java并发工具包
  • redis
  • LeetCode
  • 系统设计
  • JVM体系
Github (opens new window)
Rss (opens new window)
  • zh-CN
  • en-US
  • posts
  • Gradle Java和Groovy混编
2023-02-06

Gradle Java和Groovy混编

# Gradle Java和Groovy混编

首先安装Gradle插件

// build.gradle
plugins {
    id 'java'
    id 'groovy'
}

dependencies {
        implementation 'org.apache.groovy:groovy-all:4.0.6'
        testImplementation 'org.apache.groovy:groovy-all:4.0.6'
}

加入Gradle插件之后,编译顺序就会在compileJava​ 之后 添加一步compileGroovy​的操作。

由于存在编译顺序的关系,在java代码中引用groovy的代码时候,会编译失败。

所以需要覆盖Java的源代码路径,将所有的代码防在同一个目录下,避免编译顺序带来的问题。

在build.gradle中添加下面的代码

apply plugin: 'groovy'
//...
sourceSets {
  main {
    java { srcDirs = [] }    // no source dirs for the java compiler
    groovy { srcDirs = ["src/main/java", "src/main/groovy"] }  // compile   everything in src/ with groovy
  }
}
最近更新
01
处理Jackson反序列化问题:Cannot deserialize instance of java.lang.Integer out of VALUE_FALSE
11-28
02
Jackson单字母驼峰命名问题
11-23
03
Solution for the \Press ESC in 5 seconds to skip startup.nsh, any other key to continue\ Issue on Virtual Machine Boot in UEFI Mode
11-22
更多文章>
Theme by Vdoing | Copyright © 2015-2023 天增 | 苏ICP备16037388号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式