【发布时间】:2020-04-13 01:11:37
【问题描述】:
所以目前我正在尝试创建一个自定义 gradle 项目。 我想创建 jar(它是一个 kotlin 项目),然后获取对 jar 和该 jar 的所有依赖项的引用。
我已经在一个自定义的 maven 插件中完成了这个,它看起来像这样:
@Mojo(name = "custom-plugin", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
class CustomMavenMojo : AbstractMojo() {
@Parameter(defaultValue = "\${project}", readonly = true, required = true)
private val mavenProject: MavenProject? = null
@Throws(MojoExecutionException::class, MojoFailureException::class)
override fun execute() {
val targetFolder = File(mavenProject.model.build.directory) // the build folder
val jarFile = mavenProject.artifact.file // This is the build jar file
val dependencies = mavenProject.artifacts // The jar's dependencies
}
}
所以我可以掌握它,在 gradle 中我不得不对此有所不同。 我想我必须调用 jar 插件/任务来创建 jar,这就是它开始变得有点模糊的地方。我看到一个可以调用插件,但哪个是正确的,然后我将如何访问创建的 jar?此外,我很想了解依赖项。
这是我目前得到的:
class CustomGradlePlugin : Plugin<Project> {
override fun apply(project: Project) {
project.task("custom-jar-task") {
project.plugins.apply('???') // which plugin do i call here to create the .jar file?
val createdJar = ... // and how do i get the created jar file?
project.configurations.forEach { configuration ->
configuration.dependencies.forEach { dependency ->
val dependencyJarFile = ... // how would i get the depencenies jar file here?
}
}
}
}
}
【问题讨论】:
标签: gradle kotlin jar gradle-plugin