Hi,
Anybody can recommend a library/tool/way to manipulate Gradle build scripts in a structured way? Say, I want to transform a script by adding a plugin or removing an AppliedPlugin? How would I do that? Anybody?
Thank you!
Hi,
Anybody can recommend a library/tool/way to manipulate Gradle build scripts in a structured way? Say, I want to transform a script by adding a plugin or removing an AppliedPlugin? How would I do that? Anybody?
Thank you!
I registered this Account (my first ever here) for this. I would like to know
I have the same question. I search the interwebs. I find nearly no helpful result. I find this. This is undiscussed. Since forever. I question the interwebs. Register this account. Type this here.
Hope you had fun reading until here :]
cheers
Why is this question undiscussed since over five years?
Maybe because you needed five years to register? ![]()
Maybe because noone that has read the question had something to contribute to the discussion?
This is not some paid support platform where you can expect any reaction at all.
This is mainly a community forum where users chat with each other and help each other.
How DO i best manipulate a build.gradle file programmatically?
Best?
Probably .. not.
A build.gradle file is a Groovy script, so you can search for any way to programmatically manipulate a Groovy script.
But, well, you have a turing-complete language at hand, so it is nearly impossible to “parse and manipulate” it reliably.
Maybe you can use something like OpenRewrite or do something like that is doing, probably depends on what exactly you try to do.
With Declarative Gradle this aspect might change for the .dcl files.
yay, a quick reply
ty for that
so “this is nearly impossible in a build.gradle groovy script” … but OpenRewrite somehow can maybe do it?
guess i’m going to look into their src, thanks for this hint, too!
Also: GitHub - ben-manes/gradle-versions-plugin: Gradle plugin to discover dependency updates … i could look into that source, too, i guess. Because it finds and rewrites something in build.gradle files, too, right?
Are there other (java based?) tools (which have some utility code under the hood), that i might look into, for inspiration?
I am brainstorming about automating governance-tasks for >10 gradle projects. Gathering their state, managing (CRUD?) their state. Which also includes dependency-related things, ofc, but not only.
again, ty, for the quick //edit2: prompt reply!
cheers
Daniel
i feel a bit “red-herring-ed”, but i better understand, now. … i did not imply/assume that. But my phrasing made that “take” available.
I asked the “why-question” because i assume(d) that there must have been multiple human minds having tried smth like that in the last six years //edit: and found their way here // (the usual: it cannot be me, that is the first to stumble upon this challenge, can it?!) … which is self-defeating because - here, in this thread - this did not lead to any more discussion ![]()
Also: GitHub - ben-manes/gradle-versions-plugin: Gradle plugin to discover dependency updates … i could look into that source, too, i guess. Because it finds and rewrites something in build.gradle files, too, right?
No, it just determines updates and displays them, it does not rewrite your build script.
There are extensions for it that do it.
And there is also refreshVersions and other tools.
But my guess is, that they use heuristic textual search-and-replace, i.e. the replace some text and hope it was correct, not some semantic transformation, but I might be wrong of course.
Are there other (java based?) tools (which have some utility code under the hood), that i might look into, for inspiration?
For sure ![]()
automating governance-tasks for >10 gradle projects
Not sure what kind of governance tasks or state gathering you have in mind.
To get information from a Gradle build reliably, you would usually use the tooling API to retrieve whatever information you need. That is also the toolkit that IDEs use to get correct information about Gradle builds.
To keep multiple projects uniform and up to standards, I use in-house convention plugins and all projects use these and mainly declare what kind of project they are and what dependencies they have.