我正在IntelliJ和Idea中构建一个小Kotlin项目,并试图找出如何为我想要支持的每个操作系统创建多个tar/zip文件。
似乎分发插件(在使用应用程序插件时包含)是正确的方向,但我似乎不知道如何让它做我想做的事情。
我已经阅读了关于插件的文档,可以找到
here
,但我真的不清楚如何完成我想做的事。
分发插件可以这样做吗?如果没有,有人能提出不同的解决方案吗?
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.2.61'
}
apply plugin: 'application'
mainClassName = "MainKt"
version '1.0-SNAPSHOT'
repositories {
// my common required repos
}
dependencies {
// my common dependencies
}
distributions {
macos {
contents { from 'src' }
applicationDefaultJvmArgs.push("-XstartOnFirstThread")
dependencies {
implementation "org.eclipse.swt:org.eclipse.swt.cocoa.macosx.x86_64:4.5.2"
}
}
linux {
contents { from 'src' }
dependencies {
implementation "org.eclipse.swt:org.eclipse.swt.gtk.linux.x86_64:4.5.2"
}
startScripts.doLast {
def lines = unixScript.text.readLines()
println lines.add(1, '# add some stuff')
println lines.add(2, '# add some more stuff')
unixScript.text = lines.join("\n")
}
}
windows {
contents { from 'src' }
dependencies {
implementation "org.eclipse.swt:org.eclipse.swt.win32.win32.x86_64:4.5.2"
}
}
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
更新
这是我现在正在做的,但我想在这方面有所改进。
def deploy = false
if (!deploy) {
applicationDefaultJvmArgs.push("-XstartOnFirstThread")
dependencies {
implementation "org.eclipse.swt:org.eclipse.swt.cocoa.macosx.x86_64:4.5.2"
}
} else {
dependencies {
implementation "org.eclipse.swt:org.eclipse.swt.gtk.linux.x86_64:4.5.2"
}
startScripts.doLast {
def lines = unixScript.text.readLines()
println lines.add(1, 'export foo=foo')
println lines.add(2, 'export bar=bar')
}
}
现在我在mac上开发,并将deploy设置为false。当我想为linux生成发行版时,我将deploy设置为true。我可以为windows添加更多的代码并执行相同的操作,但我只想在一个任务中生成所有代码,并将其放在不同的tar/zip文件中。