dependency-analysis-gradle-plugin icon indicating copy to clipboard operation
dependency-analysis-gradle-plugin copied to clipboard

[TestKit Plugin] Open Rendered elements to be able to create custom ones

Open friscoMad opened this issue 11 months ago • 1 comments

Is your feature request related to a problem? Please describe. TestKit support lib is great but it only supports a small set of elements to be used in the project. It is nice that you can write project builds so easily from Kotlin code but there are not a lot of options to add custom code. For example, I have stumbled recently with not being able to add imports to build.gradle.kts or adding custom code inside the dependency or repository block.

Describe the solution you'd like After thinking about this it would be great to change all rendered elements to be open, so we can implement our own objects that render the code as needed.

Describe alternatives you've considered Another alternative would be to add more options to pass custom code or create more elements, but it will be difficult to maintain/test and will add a lot of complexity to the API it is probably impossible to model the whole language that can be used in builds without writing another language.

Additional context

My use case was trying to replicate what we use in our projects which is something like this:

import foo.bar.dependency.addTestDependencies

dependencies {
    addTestDependencies()
 }

In this case imports are just impossible to write with the current API and creating a custom BuildScriptBlock would allow it. The actual call can be rendered with the current logic in a hacky way.

Anyway, we will be moving to a catalog and bundles so we will move to a more standard practice. But imports are needed for other use cases and there is no way in Kotlin to call extension functions without an import (except via reflection)

friscoMad avatar Mar 15 '24 11:03 friscoMad

Thanks for the issue. I actually think it would make sense to add a new data type for imports, since they have to go at the top of a file, are semantically separable from other elements, and are a common-enough use-case to be worth supporting directly. The rest of this request, opening up the objects to permit custom rendering, is also interesting and I will think about it. Do you have any other use-cases in mind?

autonomousapps avatar Mar 29 '24 17:03 autonomousapps

Hi! I recently added support for imports, which is implemented essentially as a wrapper around List<String>. You should be able to use that for your needs. I'm going to close this issue. If you feel like it was closed incorrectly, please let me know.

autonomousapps avatar Aug 19 '24 18:08 autonomousapps