8000 Inject classpath for Gradle plugin functional tests by 3flex · Pull Request #5149 · detekt/detekt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Inject classpath for Gradle plugin functional tests #5149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

3flex
Copy link
Member
@3flex 3flex commented Jul 29, 2022

An alternative to #4905

I took the approach of reverse engineering the Gradle functionality that allows plugin classpaths to be injected when using TestKit. This custom solution can't yet go as far as making the injected classpath directly accessible in the build under test, as the TestKit plugin classpath injection uses some code in TestKit itself to make that seamless, which we can't take advantage of. I have some thoughts on how to possibly make it work, but it's complex and might be better explored in a future PR.

I will likely tweak the DSL and add a little more functionality into InjectedDependenciesPlugin but I think this is good enough for an initial review.

@3flex 3flex requested a review from cortinico July 29, 2022 04:47
@3flex 3flex changed the title Inject classpath for functional tests Inject classpath for Gradle plugin functional tests Jul 29, 2022
Copy link
Member
@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this @3flex, this is great!

I have some thoughts on how to possibly make it work, but it's complex and might be better explored in a future PR.

As you said, it looks a bit brittle :/ Should we touch base with someone at Gradle and ask for some support here?

As a workaround, having the CI fake a version publishing on CI would catch the same kind of issues (i.e. bump the version number, run publishToMavenLocal, run build). Agree that is suboptimal, but is more maintanaible.

@3flex
Copy link
Member Author
3flex commented Jul 31, 2022

As you said, it looks a bit brittle

I actually didn't say the solution in this PR was brittle, I was suggesting it might not be so easy to make the dependencies directly available to the build under test, so that next step would be more complex. Though it can be done manually in the meantime, as you see in this POC.

What part of this do you see as being brittle? I said "reverse engineered" but should have said "adapted the code Gradle is using", namely the pluginUnderTestMetadata task and its configuration, and how the classpath is read by TestKit.

So there's nothing novel about this solution. It needs a little refactoring (and I realise the extension is pointless as there's only a single task, so I'll remove that to simplify), but this should work just as reliably as the TestKit plugin classpath injection that TestKit itself uses.

This avoids using the dependencies from the included build
< 8000 div id="event-7095756292" data-view-component="true" class="TimelineItem js-targetable-element">
@cortinico
Copy link
Member

What part of this do you see as being brittle? I said "reverse engineered" but should have said "adapted the code Gradle is using", namely the pluginUnderTestMetadata task and its configuration, and how the classpath is read by TestKit.

Maybe is just my personal taste, but having to inject the classpath using string manipulation and populating the build.gradle of the test with our crafted string, seems brittle to me.

I understand that this aligns to what TestKit is doing internally, so I'm fine with it. I would have preferred to have an official solution to this problem provided by Gradle, but seems like this is the best we can do so far.

As a side note: please leave comments around on why this is needed, as it's not straightforward from reading the code, especially if you have no idea about how Gradle works internally

@github-actions
Copy link

This PR is stale because it has been open 90 days with no activity. Please comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Oct 30, 2022
@3flex
Copy link
Member Author
3flex commented Oct 30, 2022

I'll reopen when I come back to this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0