gradle - How to configure Gradle Java plugin from a custom Gradle plugin
问题描述
I've written a custom Gradle plugin in Kotlin 1.2.50 for use with Gradle 4.8.
I've successfully applied the Java plugin from my plugin's apply method:
override fun apply(project: Project) {
project.pluginManager.apply(JavaPlugin::class.java)
// configure Java plugin here
}
How do I configure the Java plugin?
e.g., I want to achieve the equivalent of the following that would normally be in a build.gradle.kts
:
java {
sourceCompatibility = VERSION_1_10
targetCompatibility = VERSION_1_10
}
解决方案
我挖掘了 Gradle 代码并找到了解决方案:
override fun apply(project: Project) {
project.pluginManager.apply(JavaPlugin::class.java)
val javaPlugin = project.convention.getPlugin(JavaPluginConvention::class.java)
javaPlugin.sourceCompatibility = VERSION_1_10
javaPlugin.targetCompatibility = VERSION_1_10
}
推荐阅读
- flutter - 向 MaterialPageRoute 添加过渡
- javascript - 嘿,我怎样才能验证用户名和密码?似乎javascript没有得到值
- mysql - MySQL 事件未按计划运行
- r - R - 访问函数内的变量“名称”
- python - 我如何获取表上的值并将其保存到变量中
- go - 如何将 []uint8 转换为字符串
- clang - clang __asm__ 在 case 语句中带有标签,得到错误:指令的操作数无效
- hibernate - Hibernate:persistence.xml 中的错误 - 元素“persistence-unit”不能包含文本内容。内容类型被定义为仅元素
- sql - ORA-00904: : Oracle Life 数据库中的标识符无效
- optimization - 是否有可能在 Rust 中获得整数的本机 CPU 大小?