This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kts): enhance codegen to add multiple dependencies
This means that now you can quickly add multiple dependencies in the `dependencies {}` block using shorthand function, which eliminates the need for repetitive configuration function calls: ```kotlin dependencies { implementationOf( "com.example:library:1.0.0", "foo.bar:common:0.1.0", "a.b:c:0.1.0" config { isTransitive = true }, ) } ``` Instead of: ```kotlin dependencies { implementation("com.example:library:1.0.0") implementation("foo.bar:common:0.1.0") implementation("a.b:c:0.1.0") { isTransitive = true } } ```
- Loading branch information
Showing
9 changed files
with
427 additions
and
5 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...ore-configuration/kotlin-dsl/src/main/kotlin/com/meowool/cradle/ConfigurableDependency.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.meowool.cradle | ||
|
||
import org.gradle.api.Action | ||
|
||
/** | ||
* Represents a dependency with configuration. | ||
* | ||
* @author chachako | ||
*/ | ||
data class ConfigurableDependency( | ||
/** | ||
* The dependency notation to be configured by [configuration]. | ||
*/ | ||
val notation: Any, | ||
|
||
/** | ||
* The configuration action to be applied to the dependency [notation]. | ||
*/ | ||
val configuration: Action<Any>, | ||
) |
83 changes: 83 additions & 0 deletions
83
...onfiguration/kotlin-dsl/src/main/kotlin/com/meowool/cradle/ConfigurableDependencyScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.meowool.cradle; | ||
|
||
import org.gradle.api.artifacts.Dependency | ||
import org.gradle.api.artifacts.ExternalModuleDependency | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.provider.ProviderConvertible | ||
|
||
/** | ||
* Provides advanced DSL to configure dependencies. | ||
* | ||
* @author chachako | ||
*/ | ||
interface ConfigurableDependencyScope { | ||
/** | ||
* Add [configuration] for this dependency. | ||
* | ||
* Example: | ||
* ``` | ||
* "com.example:library:1.0" config { | ||
* transitive = false | ||
* } | ||
* ``` | ||
*/ | ||
infix fun String.config(configuration: ExternalModuleDependency.() -> Unit) = ConfigurableDependency(this) { | ||
configuration.invoke(this as ExternalModuleDependency) | ||
} | ||
|
||
/** | ||
* Add [configuration] for this dependency. | ||
* | ||
* ``` | ||
* provider { "com.example:library:1.0" } config { | ||
* transitive = false | ||
* } | ||
* ``` | ||
*/ | ||
infix fun Provider<*>.config(configuration: ExternalModuleDependency.() -> Unit) = ConfigurableDependency(this) { | ||
configuration.invoke(this as ExternalModuleDependency) | ||
} | ||
|
||
/** | ||
* Add [configuration] for this dependency. | ||
* | ||
* ``` | ||
* dependency config { | ||
* transitive = false | ||
* } | ||
* ``` | ||
*/ | ||
infix fun ProviderConvertible<*>.config(configuration: ExternalModuleDependency.() -> Unit) = ConfigurableDependency(this) { | ||
configuration.invoke(this as ExternalModuleDependency) | ||
} | ||
|
||
/** | ||
* Add [configuration] for this dependency. | ||
* | ||
* ``` | ||
* project(":core") config { | ||
* transitive = false | ||
* } | ||
* ``` | ||
*/ | ||
infix fun <T : Dependency> T.config(configuration: T.() -> Unit) = ConfigurableDependency(this) { | ||
@Suppress("UNCHECKED_CAST") | ||
configuration.invoke(this as T) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.