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

test-jar dependency type is not properly handled with Gradle #1159

Open
williamsuane opened this issue Dec 4, 2020 · 8 comments
Open

test-jar dependency type is not properly handled with Gradle #1159

williamsuane opened this issue Dec 4, 2020 · 8 comments

Comments

@williamsuane
Copy link

Generating new Gradle projects that contains testImplementation("org.springframework.cloud:spring-cloud-stream:test-binder@test-jar") fails with the following message when building

Could not find org.springframework.cloud:spring-cloud-stream:test-binder.
Required by:
    project :

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

How to replicate

Generate a new project Spring Boot 2.4, Java 11, Cloud Stream and Kafka Binder

Run ./gradlew build

The solution that worked was to replace testImplementation("org.springframework.cloud:spring-cloud-stream:test-binder@test-jar") by

testImplementation("org.springframework.cloud:spring-cloud-stream") {
        artifact {
            name = "spring-cloud-stream"
            extension = "jar"
            type ="test-jar"
            classifier = "test-binder"
        }
    }
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 4, 2020
snicoll added a commit to spring-io/start.spring.io that referenced this issue Dec 7, 2020
@snicoll snicoll changed the title Gradle org.springframework.cloud:spring-cloud-stream:test-binder@test-jar fails test-jar dependency type are not properly handled with Gradle Dec 19, 2020
@snicoll snicoll self-assigned this Dec 19, 2020
@snicoll snicoll added type: bug and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 19, 2020
@snicoll snicoll added this to the 0.10.0 milestone Dec 19, 2020
@snicoll
Copy link
Contributor

snicoll commented Dec 19, 2020

@williamsuane thanks for the report.

With the help of @wilkinsona, we've been reminded that Maven handles certain dependency type with "magic strings", see the documentation. To make things consistent between the two model we may need to handle these too considering that type is a shared attribute between the two models.

@snicoll
Copy link
Contributor

snicoll commented Dec 19, 2020

So that works but, unfortunately, requesting the jar without a type fails as the dependency is not found in the bom. It is declared like this (correctly according to Maven):

			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-stream</artifactId>
				<version>${spring-cloud-stream.version}</version>
				<type>test-jar</type>
				<scope>test</scope>
				<classifier>test-binder</classifier>
			</dependency>

With the following: testImplementation 'org.springframework.cloud:spring-cloud-stream:test-binder we get:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileTestJava'.
> Could not resolve all files for configuration ':testCompileClasspath'.
   > Could not find org.springframework.cloud:spring-cloud-stream:test-binder.
     Required by:
         project :
   > Could not find org.springframework.cloud:spring-cloud-stream:test-binder.
     Required by:
         project :

Ignoring the type won't fix this issue as we need to definition to match what's in the bom.

snicoll added a commit to snicoll/initializr that referenced this issue Dec 19, 2020
@snicoll snicoll changed the title test-jar dependency type are not properly handled with Gradle test-jar dependency type is not properly handled with Gradle Dec 19, 2020
@wilkinsona
Copy link
Contributor

I'm a bit surprised that doesn't work. We could probably fix it with a change in the dependency management plugin. It would also be interesting to know how it behaves when using Gradle's Platform support.

@snicoll snicoll modified the milestones: 0.10.0, 0.11.0, 0.10.1 Feb 18, 2021
@snicoll snicoll modified the milestones: 0.10.1, 0.11.0 Mar 23, 2021
@HackerTheMonkey
Copy link

I've just came across the same issue with a project I am working on which uses SpringBoot and SpringCloud with maven.

Adding the dependency on the test binder jar in this manner:

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
            <scope>test</scope>
            <classifier>test-binder</classifier>
            <type>test-jar</type>
        </dependency>

results in that maven picking up the default classifier for test-jars which is tests instead of the overridden test-binder

Failure to find org.springframework.cloud:spring-cloud-stream:jar:tests:3.1.2 in ...

Now, removing the type from the above dependency declaration makes maven complain about the missing version, but now it uses the correct classifier, i.e. test-binder

'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-stream:jar:test-binder is missing

Adding a version, then fixes everything and the correct jar is downloaded from Maven Central

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
            <scope>test</scope>
            <classifier>test-binder</classifier>
            <version>3.1.2</version>
        </dependency>

And we get a BUILD SUCCESS. Here we can see that the classifier is indeed test-binder and not tests

@snicoll snicoll modified the milestones: 0.11.0, 0.11.1 Sep 9, 2021
@snicoll snicoll modified the milestones: 0.11.1, 0.12.0 Oct 28, 2021
@dinvlad
Copy link

dinvlad commented Dec 13, 2021

Any updates on this one?

@snicoll
Copy link
Contributor

snicoll commented Dec 13, 2021

@dinvlad this issue has all the latest update. We don't have time to work on this at the moment, I am afraid.

@snicoll snicoll removed their assignment Dec 13, 2021
@snicoll snicoll removed this from the 0.12.0 milestone Jan 21, 2022
@ashwathirao
Copy link

Gradle project with spring-cloud-stream does not build, Mockito dependency fails on build due to "org.springframework.cloud:spring-cloud-starter-config" Any updates on this ?

@negwu01
Copy link

negwu01 commented Dec 20, 2022

I tried the solution provided by @HackerTheMonkey for spring boot 3 and spring cloud v2022.0.0 when updating a project but ran into the same issue:

org.springframework.cloud:spring-cloud-stream:jar:test-binder:4.0.0 was not found in https://repo.maven.apache.org/maven2 during a previous attempt

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

No branches or pull requests

8 participants