当前位置: 首页 > 知识库问答 >
问题:

gradle6. x kotlinSpring引导罐发布失败,需要gradle-kotlin-dsl中的变通方法

孙化
2023-03-14

格雷德尔6。x发行说明告诉我们,maven publishing引导jar不起作用,因为默认的jar任务被Spring Boot插件禁用。

解决方法是告诉Gradle上传什么。如果要上载bootJar,则需要配置传出配置以完成此操作:

configurations {
   [apiElements, runtimeElements].each {
       it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
       it.outgoing.artifact(bootJar)
   }
}

不幸的是,我所有将此转换为gradle kotlin dsl的尝试都失败了:


configurations {
   listOf(apiElements, runtimeElements).forEach {
       it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
       it.outgoing.artifact(bootJar)
   }
}

* What went wrong:
Script compilation errors:

it.outgoing.artifacts.removeAll { it.buildDependencies.getDependencies(null).contains(jar) }
                                                                             ^ Out-projected type 'MutableSet<CapturedType(out (org.gradle.api.Task..org.gradle.api.Task?))>' prohibits the use of 'public abstract fun contains(element: E): Boolean defined in kotlin.collections.MutableSet'

it.outgoing.artifacts.removeAll { it.buildDependencies.getDependencies(null).contains(jar) }
                                                                                      ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
                                                                                                             public val TaskContainer.jar: TaskProvider<Jar> defined in org.gradle.kotlin.dsl
it.outgoing.artifact(bootJar)
                     ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public val TaskContainer.bootJar: TaskProvider<BootJar> defined in org.gradle.kotlin.dsl

你知道如何在Gradle Kotlin DSL中实现这个groovy解决方案吗?

共有1个答案

苏磊
2023-03-14

jarbootJar似乎是Gradle任务。您可以在静态编程语言DSL中获得对任务的引用,如下所示:

configurations {
   listOf(apiElements, runtimeElements).forEach {
       // Method #1
       val jar by tasks
       it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }

       // Method #2
       it.outgoing.artifact(tasks.bootJar)
   }
}
 类似资料:
  • 如何发布项目的Jar包? 我发现,classes.Jar位于下,我认为这是正确的Jar包(包含文件)。 是否有某种官方方法,将库释放为JAR而不是AAR? 编辑 我使用Gradle来发布Maven工件,我想发布JAR和AAR包。So基于https://chris.banes.me/2013/08/27/push-aars-to-maven-central/的带有签名、md5、manifest的JA

  • 我正在从Gradle迁移到Gradle Kotlin DSL,我有一个问题。有 在格雷德尔。

  • 报告工作的groovy代码是: 这将如何翻译成Kotlin DSL?我尝试了许多变体,其中一些编译和运行,但不创建所需的输出。可运行的罐子。

  • 我正在尝试使用静态编程语言DSL,但我无法让它识别我在BuildSrc中定义的对象。它们由IDE解析,但当我编译代码时,它不起作用。 这是我的项目结构: 依赖关系的内容: 项目build.gradle.kts(第一个失败的): 我还想指出,android{…}块在模块gradle文件中无法识别,但我认为这可能是因为编译失败。

  • 我将gradle文件从Groovy迁移到kotlin dsl。一切都很好,但是有一个问题是从另一个kotlin文件中修改值。我可以导入变量和自动完成只是工作很好,但当我构建项目时,它给我提供了未解决的引用错误。感谢任何帮助。 Gradle版本:7.1.1

  • 实际上,我也是编写/发布KSV-repository的人,所以如果我错过了一些配置,我可以在导入或导入项目中添加它。