Tag: gradle这个 Kotlin DSL

不同的方式来应用插件? (Gradle Kotlin DSL)

试图将这个项目的构建迁移到GSK。 我们在Groovy有这个: allprojects { apply plugin: ‘java’ … sourceSets { … } sourceCompatibility = … } 因此,在搞清楚如何访问Kotlin的插件约定时,我发现: allprojects { plugins { java apply true } … println(“Project $name, plugins: ${plugins}”) // empty list val java = the() // throws exception } 但如果你这样做: allprojects { apply { plugin(JavaPlugin::class.java) } } 插件被应用并且惯例变得可访问 WTH?

用gradle kotlin-dsl覆盖spring引导依赖版本

SpringBoot带有很多的依赖和默认版本。 在groovy-gradle中,这样的依赖版本可以被覆盖: ext[‘mockito.version’] = ‘1.7.5’ 但是这不适用于kotlin-dsl。 我试过了: val mockito by extra { “2.12.0” } val mockito.version by extra { “2.12.0” } val `mockito.version` by extra { “2.12.0” } 后两者,不编,第一个,没有做这个工作。 如何在kotlin文件中覆盖版本(我不想创建一个单独的属性文件,如果它是某种可能的话)。

使用Gradle Kotlin配置Maven插件

试图将项目转换为GSK 我们在Groovy有这个: subprojects { plugins.withType(MavenPlugin) { tasks.withType(Upload) { repositories { mavenDeployer { mavenLocal() repository(url: “xxx”) { authentication(userName: “yyy”, password: “zzz”) } snapshotRepository(url: “xxx”) { authentication(userName: “yyy”, password: “zzz”) } pom.artifactId = “${project.name}” pom.version = “$version” } } } } } 在GSK,我得到了这么多: plugins.withType(MavenPlugin::class.java) { tasks.withType(Upload::class.java) { val maven = the() maven.mavenDeployer { // ??? } } […]

在gradle-kotlin-dsl中的Android产品Flavors

我已经在Android项目中尝试了gradle-kotlin-dsl。 我设法使其工作,但我坚持如何定义productFlavors android { compileSdkVersion(Config.Android.compileSdkVersion) buildToolsVersion(Config.Android.buildToolsVersion) defaultConfig { minSdkVersion(Config.Android.minSdkVersion) targetSdkVersion(Config.Android.targetSdkVersion) versionCode = Config.Version.code versionName = Config.Version.name } buildTypes { getByName(“release”) { isMinifyEnabled = false } } flavorDimensions(“dimension”) productFlavors { //product flavors here } } 经过一番调查,我已经得到了解决方案,只需使用create方法: productFlavors { create(“flavor1”) { //flavor configurations here } create(“flavor2”) { //flavor configurations here } }

我怎样才能用Kotlin DSL为Gradle配置Kotlin协程?

在Kotlin-DSL中使用Gradle 4.4.1,我想在我的Kotlin 1.2.20项目中配置实验Kotlin协同程序。 这certificate是非常困难的。 官方的Kotlin文档本身只提到Gradle和Groovy DSL,而不是Kotlin。 Kotlin-DSL项目有一个协程不起作用的例子 。 可能是为了一个较老的Gradle版本(该脚本中的Kotlin版本是1.1.51,本身是可疑的)。 PS:即使IntelliJ的配置Kotlin写不正确的Gradle代码。 降级唯一的选择? 附录:构建脚本在IntelliJ IDEA中非常红 。 IDE始终添加导入语句。 看来,这些徒劳的尝试是使剧本不起作用的。 我禁用了“临时添加unambiguos导入”,即使脚本保持大部分为红色,Gradle也可以执行它。 之后,IntelliJ的错误消息也没有了。

找不到Kotlin脚本Gradle的kotlin-gradle-plugin

构建失败,类路径错误: thufir@dur:~/NetBeansProjects/kotlinShadowJar$ thufir@dur:~/NetBeansProjects/kotlinShadowJar$ gradle clean FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring root project ‘kotlinShadowJar’. > Could not resolve all files for configuration ‘:classpath’. > Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:. Searched in the following locations: file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar Required by: project : * Try: Run with […]

如何在两个build.gradle.kts文件之间共享构建配置?

我有两个项目(在一个单一的git仓库),应该有相同的 repository { } 部分在他们的build.gradle.kts ,但是完全不相关。 我可以把这个共同的部分,包括在每个分别build.gradle.kts ? 怎么样?

如何将ext。*变量转换为build.gradle.kts中的插件块

我的构建文件如下所示: val nexusBaseUri: String by extra val gradle_version: String by extra val kotlin_version: String by extra buildscript { val nexusBaseUri by extra { "https://mynexusserver/nexus" } val gradle_version by extra { "4.1" } val kotlin_version by extra { "1.1.4-3" } val springBoot_version by extra { "2.0.0.M3" } repositories { maven { url = uri("$nexusBaseUri/repository/public") } jcenter() […]

Gradle KTS。 如何将依赖关系配置从主构建移动到单独的文件?

我试图在kotlin中创建模块化的构建脚本。 基本上主要的脚本和依赖脚本。 在build.gradle.kts我有: applyFrom("dependencies.kts") 并在dependencies.kts我有实际的依赖关系: dependencies { listOf( kotlinModule("stdlib-jre8"), // Spring boot "org.springframework.boot:spring-boot-starter-web", "org.springframework.boot:spring-boot-starter-security", "org.springframework.boot:spring-boot-starter-logging", "org.springframework.boot:spring-boot-actuator", // Spring "org.springframework.data:spring-data-mongodb", // Logging "org.slf4j:slf4j-api", "org.slf4j:jcl-over-slf4j", "ch.qos.logback:logback-classic" ).forEach { compile(it) } listOf( "org.codehaus.groovy:groovy-all", "org.springframework.boot:spring-boot-starter-test", "org.spockframework:spock-core:1.0-groovy-2.4", "org.spockframework:spock-spring:1.0-groovy-2.4" ).forEach { testCompile(it) } } 这失败了: Error: Could not find method kotlinModule() for arguments [stdlib-jre8] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. 如果我尝试导入kotlinModule,则失败: Error:Cause: […]

使用gradle-script-kotlin的ant任务

我如何从我的build.gradle.kts脚本访问ant任务? 特别是,我对ant.patch任务感兴趣。 我可以像这样扩展它吗? task("patchSources", Patch::class) { 我可以从其他任务调用它,像这样吗? task("patchSources") { doLast { ant.patch(…) } } 我知道如何在Groovy中做到这一点: 如何在Gradle中应用补丁文件?