[英]Building gradle plugin
I'm developing a gradle plugin alongside with a project: 我正在与项目一起开发gradle插件:
plugin_consumer
|
+ build.gradle
+ src/
plugin
|
+ build.gradle
+ libs/
+ src/
All jars are moved to plugin/libs
after built, and plugin consumer
module uses plugin like so: 构建后,所有jar都移至
plugin/libs
,并且plugin consumer
模块使用如下插件:
buildscript {
repositories {
// ...
}
dependencies {
classpath fileTree(dir:'../plugin/libs', include: ['*.jar'])
}
}
apply plugin: 'my.custom.plugin'
I tested and this setup worked fine, however the plugin .jar
is being built without dependencies, and as soon as I add some dependencies to the project the consumer buildscript started crashing because of NoClassDefFoundError
exceptions. 我进行了测试,并且此设置运行良好,但是
.jar
插件的构建没有依赖关系,一旦我向项目添加了一些依赖关系,由于NoClassDefFoundError
异常,使用者构建脚本便开始崩溃。 The problem is when I build a fat jar instead the script no longer finds plugin: 问题是当我建立一个胖子罐时 ,脚本不再找到插件:
// from plugin/build.gradle
// Configurations to build jar with dependencies
configurations {
jar.archiveName = 'plugin.jar'
}
jar {
archiveName = 'plugin.jar'
baseName = project.name + '-all'
from { configurations.compile.collect {
println it
it.isDirectory() ? it : zipTree(it)
} }
}
Running commands on plugin_consumer
project throws error: 在
plugin_consumer
项目上运行命令会引发错误:
> Failed to apply plugin [id 'my.custom.plugin']
> Plugin with id 'my.custom.plugin' not found.
I haven't identified the problem, but have found a solution. 我没有发现问题,但是找到了解决方案。 Somehow the
jar
instruction to package all of the sources have messed up the plugin jar file. 打包所有源代码的
jar
指令以某种方式弄乱了插件jar文件。 The following configurations have worked on plugin side instead: 以下配置已在插件端起作用:
//...
jar {
from {
configurations.compileWithDependencies.collect { it.isDirectory() ? it : zipTree(it) }
}
}
configurations {
compileWithDependencies
}
dependencies {
compile gradleApi()
compileWithDependencies 'my.dependency1'
compileWithDependencies 'my.dependency1'
testCompile 'test.dependency'
configurations.compile.extendsFrom(configurations.compileWithDependencies)
}
From the looks of it I would guess that gradleApi()
dependencies should not be compiled into the plugin jar. 从外观上,我猜想
gradleApi()
依赖项不应该编译到插件jar中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.