简体   繁体   English

如何以编程方式修改build.gradle文件?

[英]How to modify build.gradle file programmatically?

Is there any way to add dependency to a gradle or maven project programmatically ? 有没有办法以编程方式向gradlemaven项目添加依赖项? I am trying to modify a java file using eclipse JDT. 我正在尝试使用eclipse JDT修改java文件。 One of my changes requires a method from apache-commons . 我的一个更改需要apache-commons的方法。 So I have to check programmatically whether the library is already included and if not I have to add the dependency. 所以我必须以编程方式检查库是否已经包含,如果不是,我必须添加依赖项。 Is there any way or tool that helps me? 有什么办法或工具可以帮助我吗?

You should not modify build file, like pom.xml or build.gradle for that needs. 您不应该修改构建文件,例如pom.xmlbuild.gradle I think, it's a better idea to check if the library is in the project's classpath and if it's not - gently ask a developer to add it. 我认为,检查库是否在项目的类路径中是否更好,如果不是 - 请轻轻地请求开发人员添加它。 That's how, for example, generating of toString works in IDEA: if certain libraries are available in the project corresponding options become available: 例如,生成toString的方法就是如何在IDEA中工作:如果项目中有某些库可用,则相应的选项可用: <code> toString()</ code>选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM