gradle / gradle

Adaptable, fast automation for all
https://gradle.org
Apache License 2.0
16.9k stars 4.73k forks source link

testFixturesAnnotationProcesor is not getting the version from the platform's constraint #19315

Open trevan opened 2 years ago

trevan commented 2 years ago

The testFixturesAnnotationProcessor is not resolving the version that is defined as a constraint in a platform.

In the attached zip file, there are two modules: platform and lib.

Platform's build.gradle is:

plugins {
  id 'java-platform'
}

dependencies {
  constraints {
    api 'org.projectlombok:lombok:1.18.20'
  }
}

Lib's build.gradle is:

lugins {
    id 'java-library'
    id 'java-test-fixtures'
}

// set the below to true to break the build, false to fix the build
ext.withoutVersion = true

dependencies {
    api platform(project(':platform'))
    implementation platform(project(':platform'))
    annotationProcessor platform(project(':platform'))

    api 'org.projectlombok:lombok'
    implementation 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'

    testImplementation 'org.projectlombok:lombok'
    testAnnotationProcessor 'org.projectlombok:lombok'

    testFixturesApi 'org.projectlombok:lombok'
    testFixturesImplementation 'org.projectlombok:lombok'
    if (withoutVersion == true) {
        testFixturesAnnotationProcessor 'org.projectlombok:lombok'
    } else {
        testFixturesAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
    }
}

If you run build with withoutVersion set to false, then the build succeeds. The dependencies defined in testFixturesApi and testFixturesImplementation all resolve correctly from the platform and testFixturesAnnotationProcessor resolves because there is a version specified. But if you change withoutVersion to true, then the build will fail. It complains about unable to resolve org.projectlombok:lombok.

Expected Behavior

The platform constraints should be used by testFixturesAnnotationProcessor just like api, implementation, annotationProcessor, testImplementation, testAnnotationProcessor, testFixturesApi, and testFixturesImplementation.

Current Behavior

testFixturesAnnotationProcessor is not utilizing the platform constraints and requires a version to be specified.

Context

Steps to Reproduce

annotationProcessorBug.zip

Your Environment

Build scan URL:

ljacomet commented 2 years ago

This is most likely caused by the testFixturesAnnotationProcessor configuration not having any kind of relationship with the main annotationProcessor configuration.

I am actually surprised that it works between annotationProcessor and testAnnotationProcessor.

The easy fix is to add the platform to the testFixturesAnnotationProcessor configuration as you've done for others.

I'll keep digging to figure out why it works between main and test.

harshSE commented 1 year ago

@ljacomet , if there have been any recent updates or changes related to adding the platform to the testFixturesAnnotationProcessor.