Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Fix usabililty of Configuration accessors in the configurations {} block #1129

Merged
merged 5 commits into from
Sep 24, 2018

Conversation

eskatos
Copy link
Member

@eskatos eskatos commented Sep 21, 2018

by generating accessors to the existing container elements, leveraging NamedDomainObjectCollection.collectionSchema.

Those extensions expose the internal DefaultConfiguration type because of gradle/gradle-native#856

Old accessors removed as they conflict with the new and work in less situations. Extensions were added to provide source-compatibility to scripts that were using the old accessors, marked as deprecated and with IDE guidance for replacement.

With the example from the original report in #1118 this is now possible:

configurations {
    implementation {
        exclude(group = "org.foo")
    }
}

and introduce deprecated extensions to keep source-compatibility

Signed-off-by: Paul Merlin <[email protected]>
@@ -125,6 +140,10 @@ private
val typeOfProject = typeOf<Project>()


private
val typeOfConfigurationContainer = typeOf<NamedDomainObjectContainer<Configuration>>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Since we're getting those elements specifically from project.configurations, wouldn't it be better to limit the extensions to ConfigurationContainer only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't because configurations {} receiver is NamedDomainObjectContainerScope<Configuration>.



@Deprecated(deprecationMessage, replaceWith = ReplaceWith("get().buildDependencies"))
val <T : Configuration> NamedDomainObjectProvider<T>.buildDependencies: TaskDependency
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ should have kdoc pointing to the delegate method

@@ -46,8 +47,8 @@ class ScriptHandlerScope(scriptHandler: ScriptHandler) : ScriptHandler by script
/**
* The script classpath configuration.
*/
val ConfigurationContainer.classpath: Configuration
get() = getByName(CLASSPATH_CONFIGURATION)
val NamedDomainObjectContainer<Configuration>.classpath: NamedDomainObjectProvider<Configuration>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because configurations {} receiver is NamedDomainObjectContainerScope<Configuration>.

configurations = emptyList()
)
}


private
enum class EntryKind { Extension, Convention }
fun <T> ProjectSchema<T>.flatMapGroupedByEntryKind() =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entriesPairedWithEntryKind()?

@eskatos
Copy link
Member Author

eskatos commented Sep 22, 2018

@bamboo this is ready for another round

@eskatos eskatos merged commit 2eb8f6b into develop Sep 24, 2018
@eskatos eskatos deleted the eskatos/configurations/fix-accessors branch September 24, 2018 17:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants