Skip to content
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

Gradle is not resolving DependencyHandler methods for test sets #125

Open
AlbRoehm opened this issue Oct 2, 2021 · 2 comments
Open

Gradle is not resolving DependencyHandler methods for test sets #125

AlbRoehm opened this issue Oct 2, 2021 · 2 comments

Comments

@AlbRoehm
Copy link

AlbRoehm commented Oct 2, 2021

Gradle Wrapper Version 7.1

I was trying to add a dependency to the test library module i defined like this:

testSets {
    createLibrary("testCommon")
    create("testIntegration"){
        imports("testCommon")
    }
    unitTest{
        imports("testCommon")
    }
}

According to the documentation i expected to be able to add dependency in the following syntax.

dependencies{
   ...
    testCommonImplementation("io.ktor:ktor-gson:$ktorVersion")
    testCommonImplementation("com.karumi.kotlinsnapshot:core:2.2.3")
}

Gradle was not able to resolve the function and add the dependencies correctly until i added the following function which solved it:

fun DependencyHandler.testCommonImplementation(dependencyNotation: Any): Dependency? =
    add("testCommonImplementation", dependencyNotation)

Could someone clarify if one is supposed to do it this way? Being not that well versed with gradle this gave me quite the headache

@AlbRoehm AlbRoehm changed the title Gradle is not resolving DependencyHandler methods for tests sets Gradle is not resolving DependencyHandler methods for test sets Oct 6, 2021
@knes1
Copy link

knes1 commented Nov 18, 2021

I believe that what you experienced is the limitation of Gradle's Kotlin DSL, at least according to the similar issue already reported here: #109

So, to answer your question, it seems like one is in fact supposed to it the way you described. Alternative would be:

dependencies{
   ...
    "testCommonImplementation"("io.ktor:ktor-gson:$ktorVersion")
    "testCommonImplementation"("com.karumi.kotlinsnapshot:core:2.2.3")
}

I like your extension function approach as another alternative to overcome the aforementioned limitation.

@AlbRoehm
Copy link
Author

AlbRoehm commented Nov 18, 2021

Thanks for the clarification and example! I stumbled upon the kotlin dsl on some other stuff too ...

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

No branches or pull requests

2 participants