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

Update annotations so they don't require a @get: prefix in Kotlin #28459

Open
aSemy opened this issue Mar 14, 2024 · 5 comments
Open

Update annotations so they don't require a @get: prefix in Kotlin #28459

aSemy opened this issue Mar 14, 2024 · 5 comments
Labels
a:feature A new functionality in:writing-tasks task option

Comments

@aSemy
Copy link
Contributor

aSemy commented Mar 14, 2024

Current Behaviour

  • Kotlin requires a more verbose syntax, which adds unnecessary noise, obscuring the meaning of the code.
  • The annotations Gradle requires require inconsistent syntax.
  • Requiring prefixing annotations with get: doesn't prevent invalid code, for example with @Input functions that don't match the naming scheme getFoo()
abstract class MyTask
@Inject                             // a normal annotation, no prefix required ✅
constructor(
  private val objects: ObjectFactory
): DefaultTask() {
  @get:Input                        // `get:` prefix required, but this noisy and redundant ❌
  abstract val a1: Property<String> // it's already a read-only val

  @get:Input                        // `get:` prefix required, but this noisy and redundant ❌
  val a2: Property<String> get() = objects.property()

  @Input                            // a normal annotation, no prefix required ✅
                                    // Inconsistent with a1 & a2, because no `get:` prefix required ❌
  val a3: Property<String> = objects.property()


  @Input                            // a normal annotation, no prefix required ✅
                                    // Inconsistent with a1, because no `get:` required ❌
  fun b1(): Provider<String> = a1   // Also, function is invalid because it isn't named `getB1()`
}

Expected Behaviour

  • I don't need to add @get: prefix when writing annotations.
  • The annotations Gradle requires can be written consistently.
abstract class MyTask
@Inject                             // a normal annotation, no prefix required ✅
constructor(
  private val objects: ObjectFactory
): DefaultTask() {
  @Input                            // no `get:` prefix required ✅
  abstract val a1: Property<String> // it's already a read-only val

  @Input                            // no `get:` prefix required ✅
  val a2: Property<String> get() = objects.property()

  @Input                            // a normal annotation, no prefix required ✅
                                    // Consistent with a1 & a2, because no `get:` prefix required
  val a3: Property<String> = objects.property()


  @Input                            // Consistent with a1, because no `get:` required ✅
  fun b1(): Provider<String> = a1   // However, function is invalid because it isn't named `getB1()`
}

Note that requiring prefixing annotations with get: doesn't prevent invalid code, for example with @Input functions that don't match the naming scheme getFoo()

Context

  • Gradle is more difficult to understand for beginners.
  • Annotating task inputs has unnecessary friction.
  • Gradle promotes the Kotlin DSL as the primary language, and so it makes sense to update the existing annotations so they are easier to use.
@aSemy aSemy added a:feature A new functionality to-triage labels Mar 14, 2024
@Vampire
Copy link
Contributor

Vampire commented Mar 14, 2024

Just as additional information as I had a cursory look already.
I think to support something like that, you would need annotations that are written in Kotlin so that they can have the property target.
And additionally the description of that target says "annotations with this target are not visible to Java", so you would most probably also need the consuming code in Kotlin so that it can see those annotations with "property" target.

@ov7a ov7a added in:kotlin-dsl in:writing-tasks task option 👋 team-triage Issues that need to be triaged by a specific team and removed to-triage labels Mar 14, 2024
@ov7a
Copy link
Member

ov7a commented Mar 14, 2024

This issue needs a decision from the team responsible for that area. They have been informed. Response time may vary.


Another question that might be interesting on this topic is: How will these annotations work with Java Records?

@eskatos
Copy link
Member

eskatos commented Apr 4, 2024

Note that a2 in the example snippet doesn't make sense as a new property would be returned each time a2 is accessed.

@Vampire
Copy link
Contributor

Vampire commented Apr 4, 2024

If you read it as

private val _a2: Property<String> = objects.property()

@get:Input
val a2: Provider<String> get() = _a2

it makes more sense.

Besides that as you have a getter, you could actually annotate the getter directly instead of the property already like

private val _a2: Property<String> = objects.property()
val a2: Provider<String> @Input get() = _a2

@lptr
Copy link
Member

lptr commented Apr 8, 2024

We should do this. Not sure when.

@lptr lptr removed the 👋 team-triage Issues that need to be triaged by a specific team label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:feature A new functionality in:writing-tasks task option
Projects
None yet
Development

No branches or pull requests

5 participants