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

Undocumented behaviour: Configuration secondary variants inherit the primary's attributes #28939

Closed
aSemy opened this issue Apr 23, 2024 · 1 comment
Labels
closed:duplicate Duplicated or superseeded by another issue

Comments

@aSemy
Copy link
Contributor

aSemy commented Apr 23, 2024

Issue type

Wrong or misleading information

Problem description

Current Behaviour

Configuration secondary variants inherit the primary's attributes. This behaviour is unexplained and undocumented.

Expected Behaviour

Either:

  1. The behaviour is a bug, and Configuration secondary variants should not inherit attributes.

  2. The behaviour is intentional, and should be documented.

    (Note: It would be much appreciated if the current behaviour should not just be written down, but also explained to give context. For example, by answering these questions: Why should attributes be automatically inherited? Why would this be advantageous? In what situations is this relevant? Apparently, the inherited attributes can be overridden - when should this be done, if at all?)

Context

Related: #28149

I reported this previously #28811, but it was incorrectly closed by @ov7a as a duplicate of an unrelated issue.

Steps to Reproduce

// build.gradle.kts

group = "x.y.z"
version = "1.2.3"

val myFooAttribute = Attribute.of("FooAttribute", String::class.java)
val myFooVariantAttribute = Attribute.of("FooVariantAttribute", String::class.java)

val fooFiles: Configuration by configurations.creating {
  isCanBeDeclared = false
  isCanBeResolved = false
  isCanBeConsumed = true

  attributes {
    attribute(myFooAttribute, "main")
  }
}

val fooFilesVariant1: ConfigurationVariant by fooFiles.outgoing.variants.creating {
  attributes {
    attribute(myFooVariantAttribute, "variant1")
  }
}

val fooFilesVariant2: ConfigurationVariant by fooFiles.outgoing.variants.creating {
  attributes {
    attribute(myFooAttribute, "secondary")
    attribute(myFooVariantAttribute, "variant2")
  }
}

Run gradle outgoingVariants -q

--------------------------------------------------
Variant fooFiles
--------------------------------------------------

Capabilities
    - x.y.z:proj:1.2.3 (default capability)
Attributes
    - FooAttribute = main

Secondary Variants (*)

    --------------------------------------------------
    Secondary Variant fooFilesVariant1
    --------------------------------------------------
    
    Attributes
        - FooAttribute        = main
        - FooVariantAttribute = variant1

    --------------------------------------------------
    Secondary Variant fooFilesVariant2
    --------------------------------------------------
    
    Attributes
        - FooAttribute        = secondary
        - FooVariantAttribute = variant2

(*) Secondary variants are variants created via the Configuration#getOutgoing(): ConfigurationPublications API which also participate in selection, in addition to the configuration itself.

Observations:

  • fooFiles only has FooAttribute = main, which is expected.
  • fooFilesVariant1 contains FooAttribute = main. This is unexpected behaviour, because it's not documented.
  • fooFilesVariant2 overrides FooAttribute to be FooAttribute = secondary. Because of the automatic inheritance, I'm now confused. Is overriding the primary's attributes supposed to be allowed? Is it problematic?

Gradle version

8.7

Build scan URL (optional)

No response

Your Environment (optional)

No response

Context (optional)

No response

Page with the problem

n/a

@aSemy aSemy added a:documentation Documentation content to-triage labels Apr 23, 2024
@ov7a
Copy link
Member

ov7a commented Apr 24, 2024

This issue will be closed as a duplicate of

Please add your use case and 👍 to that issue.

If you think our analysis is wrong, please provide us with more detailed information explaining why.


Sorry, I don't see this as a constructive behavior. You can dislike our decisions, but spamming like this is a waste of everybody's time.

Regarding the issue - the title of the supposedly unrelated issue is "Please improve variant/attribute documentation / error messages", and your issue is related to secondary variants. They are clearly related.

A kind reminder that this repository is a subject of CoC.

@ov7a ov7a closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2024
@ov7a ov7a added closed:duplicate Duplicated or superseeded by another issue and removed a:documentation Documentation content to-triage labels Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:duplicate Duplicated or superseeded by another issue
Projects
None yet
Development

No branches or pull requests

2 participants