This repository has been archived by the owner on Aug 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* embeddedKotlinVersion * DependencyHandler.kotlinModule(module: String, version: String?) * RepositoryHandler.gradleScriptKotlin() Resolves #94 Resolves #95
- Loading branch information
Showing
2 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
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
84 changes: 84 additions & 0 deletions
84
buildSrc/src/main/kotlin/codegen/GenerateKotlinDependencyExtensions.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,84 @@ | ||
/* | ||
* Copyright 2016 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 codegen | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
import java.io.File | ||
|
||
open class GenerateKotlinDependencyExtensions : DefaultTask() { | ||
|
||
@get:OutputFile | ||
var outputFile: File? = null | ||
|
||
@get:Input | ||
var embeddedKotlinVersion: String? = null | ||
|
||
@get:Input | ||
var gradleScriptKotlinRepository: String? = null | ||
|
||
@TaskAction | ||
fun generate() { | ||
outputFile!!.writeText( | ||
"""/* | ||
* Copyright 2016 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 org.gradle.script.lang.kotlin | ||
import org.gradle.api.artifacts.dsl.DependencyHandler | ||
import org.gradle.api.artifacts.dsl.RepositoryHandler | ||
import org.gradle.api.artifacts.repositories.ArtifactRepository | ||
/** | ||
* The version of the Kotlin compiler embedded in gradle-script-kotlin (currently _${embeddedKotlinVersion}_). | ||
*/ | ||
val embeddedKotlinVersion = "$embeddedKotlinVersion" | ||
/** | ||
* Adds the remote repository containing the Kotlin libraries embedded in gradle-script-kotlin. | ||
*/ | ||
fun RepositoryHandler.gradleScriptKotlin(): ArtifactRepository = | ||
maven { it.setUrl("$gradleScriptKotlinRepository") } | ||
/** | ||
* Builds the dependency notation for the named Kotlin [module] at the given [version]. | ||
* | ||
* @param module simple name of the Kotlin module, for example "reflect". | ||
* @param version desired version, null implies [embeddedKotlinVersion]. | ||
*/ | ||
fun DependencyHandler.kotlinModule(module: String, version: String? = null): Any = | ||
"org.jetbrains.kotlin:kotlin-${'$'}module:${'$'}{version ?: embeddedKotlinVersion}" | ||
""") | ||
} | ||
} |