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

Configuration.getElements() eagerly triggers artifact transforms #27372

Open
jjohannes opened this issue Dec 11, 2023 · 1 comment
Open

Configuration.getElements() eagerly triggers artifact transforms #27372

jjohannes opened this issue Dec 11, 2023 · 1 comment
Labels
a:bug has:reproducer Indicates the issue has a confirmed reproducer in:dependency-declarations variant notation attributes capability substitution in:scheduler execution plan, task graph, work lease, project lock

Comments

@jjohannes
Copy link
Contributor

Current Behavior

Using Configuration.getElements() to define lazy mapping functions on to-be-produced artifacts should not trigger artifact transforms. Such transforms run too early for locally built artifacts and can produce a wrong result or an error.

Expected Behavior

Configuration.getElements() does not trigger artifact transforms.

Context (optional)

No response

Steps to Reproduce

Reproducer project

settings.gradle.kts

include("app", "lib")

lib/build.gradle.kts

plugins { id("java-library") }

app/build.gradle.kts

plugins { id("java-library") }

abstract class IdTransform : TransformAction<TransformParameters.None> {
    @get:InputArtifact
    abstract val inputArtifact : Provider<FileSystemLocation>
    override fun transform(outputs: TransformOutputs) { outputs.file(inputArtifact) }
}
val transformed = Attribute.of("transformed", Boolean::class.javaObjectType)
configurations.runtimeClasspath { attributes.attribute(transformed, true) }
dependencies.artifactTypes.maybeCreate("jar").attributes.attribute(transformed, false)
dependencies.registerTransform(IdTransform::class) {
    from.attributes.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, "jar").attribute(transformed, false)
    to.attributes.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, "jar").attribute(transformed, true)
}

dependencies { implementation(project(":lib")) }

tasks.register<Sync>("copyRT") {
    from(configurations.runtimeClasspath.get().elements)
    destinationDir = layout.buildDirectory.dir("out").get().asFile
}

Run: gradle clean :app:copyRT

Transform triggers for non existing lib/build/libs/lib.jar

Gradle version

8.5 (reproducible with other 8.x versions and 7.6)

Build scan URL (optional)

https://scans.gradle.com/s/ktwgohxcen6zq

Your Environment (optional)

No response

@ov7a ov7a added in:dependency-declarations variant notation attributes capability substitution in:scheduler execution plan, task graph, work lease, project lock and removed to-triage labels Dec 12, 2023
@ov7a
Copy link
Member

ov7a commented Dec 12, 2023

Thank you for providing a valid report.

The issue is in the backlog of the relevant team, but this area of Gradle is currently not a focus one, so it might take a while before a fix is made.

@ov7a ov7a added the has:reproducer Indicates the issue has a confirmed reproducer label Dec 12, 2023
jjohannes added a commit to gradlex-org/extra-java-module-info that referenced this issue Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug has:reproducer Indicates the issue has a confirmed reproducer in:dependency-declarations variant notation attributes capability substitution in:scheduler execution plan, task graph, work lease, project lock
Projects
None yet
Development

No branches or pull requests

2 participants