如何获得项目扩展在gradle工具? [英] How to get the project Extensions in gradle tooling?

查看:174
本文介绍了如何获得项目扩展在gradle工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gradle工具并使用 projectConnection 我可以从java连接到gradle。通过使用 ModelBuilder ,我可以在我的java类中获得项目对象。

I'm using gradle tooling and using projectConnection I'm able to get connected to gradle from java. And by using the ModelBuilder I'm able to get the project object also in my java class.

ModelBuilder gradleBuilder = connection.model(GradleProject.class); 

但是这个项目对象可以访问任务只要。 (即) project.getTasks()可用。但不是 project.getExtensions()。如何访问这些扩展?有没有其他方法可以从Java访问gradle Extensions

But this project object has accessibility to Tasks only. (i.e) project.getTasks() is available. But not project.getExtensions(). How to access these extensions?? Is there any other way to access the gradle Extensions from Java?

在您的响应之后编辑:

运行gradle任务时,它将读取给定文件中的闭包,并更新静态java类中读取的值( deployGradleReaderExtension.java )。现在我试图从扩展中读取值。

When I run a gradle task it will read the closures in the given file and update the values read in a static java class (deployGradleReaderExtension.java). Now I'm trying to read the value from extensions by

deployGradleReaderExtension ext = (deployGradleReaderExtension) buildResult.getGradle().getRootProject().getExtensions().getByName("serviceConf");

现在我收到了投射异常。因为gradle和java正在使用diff ClassLoaders

Now I'm getting the casting exception. Because gradle and java are using diff ClassLoaders.

有没有办法克服这个问题? b $ b

Is there any way to overcome this?

推荐答案

这篇关于如何获得项目扩展在gradle工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆