使用apply from的gradle 插件脚本 不能访问某些class(Task)

Hi,

We have some plugins on our own, which we apply in our build.gradle. Also we apply a second buildscript afterwards, which handles our tests, the following way:

apply {
plugin 'ownplugin’
from ‘tests.gradle’
}

In the tests.gradle we want to create a task of a type, which classfile is located in the ownplugin.

task executeImportBla(type: mycompany.plugin.BlaTask) {
… some configuration
}

This works, if the task creation happens in the build.gradle but doesn’t work if it happens in the tests.gradle. The error is:
Caused by: groovy.lang.MissingPropertyException: Could not find property ‘mycompany’ on root project ‘project’.
at org.gradle.api.internal.AbstractDynamicObject.propertyMissingException(AbstractDynamicObject.java:43)
at org.gradle.api.internal.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:3

If I add an import of the taskclass before and only use simplename when creating task, the class could not be found when importing. And again: in build.gradle the whole stuff is working.

Is this a bug or do I try to do something that is not possible?

Any help welcome,
Thank you
Markus

 

回答

Script plugins do not have access to the main buildscript classpath.

You could:

  • add a dependency on mycompany.plugin to tests.gradle using the buildscript {} syntax
  • push the logic from tests.gradle into a plugin class in the buildSrc folder of your project, giving you the added benefit of more IDE support when editing it

转载于:https://my.oschina.net/sfshine/blog/2236921

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值