我想将我的项目打包在一个可执行的JAR中进行分发.
如何将所有依赖JAR的Maven项目打包到我的输出JAR中?
到目前为止,我通过Eclipse"Export ..."功能创建了可运行的JAR文件,但现在我切换到IntelliJ IDEA和Gradle进行构建自动化.
这里的一些文章提出了"应用程序"插件,但这并不完全导致我期望的结果(只是一个JAR,没有启动脚本或类似的东西).
如何通过Eclipse"Export ..."对话框实现相同的结果?
如何使用gradle将配置文件或任何其他资源添加到我的jar中?
我的项目结构:
src/main/java/com/perseus/.. --- Java包(源文件)
src/main/java/config/*.xml --- Spring配置文件
预期的罐子结构:
com/perseus/.. --- Java包(类文件)
config/*.xml --- Spring配置文件
我已经编写了一个简单的kotlin源文件以便开始使用,还有一个gradle脚本文件.但我无法弄清楚如何将主要功能添加到清单中,以便jar可以自行执行.
这是我的build.gradle脚本:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.9.66'
}
}
apply plugin: "kotlin"
repositories {
mavenCentral()
}
dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib:0.9.66'
}
jar {
manifest {
attributes 'Main-Class': 'com.loloof64.kotlin.exps.ExpsPackage'
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的com.loloof64.kotlin.exps.Multideclarations.kt
package com.loloof64.kotlin.exps
class Person(val firstName: String, val lastName: String) {
fun component1(): String {
return firstName
}
fun component2(): String {
return lastName
}
}
fun main(args: Array < String > ) {
val(first, last) = Person("Laurent", "Bernabé")
println("First name : $first - Last …Run Code Online (Sandbox Code Playgroud) 我在Gradle 4.6中有一个简单的项目,并希望制作一个可执行的jar.我试过shadow,gradle-fatjar-plugin,gradle-one-jar,spring-boot-gradle-plugin插件,但他们都没有增加我的依赖性声明implementation(我没有任何compile的).它适用compile于gradle-one-jar插件,但我想有implementation依赖.
非常感谢你!
最简单的Kotlin hello world for gradle script Kotlin:
thufir@dur:~/github/gradleScriptKotlin$
thufir@dur:~/github/gradleScriptKotlin$ gradle clean shadowJar;java -jar build/libs/gradleScriptKotlin.jar
> Task :compileKotlin
Using Kotlin incremental compilation
> Task :shadowJar
A problem was found with the configuration of task ':shadowJar'. Registering invalid inputs and outputs via TaskInputs and TaskOutputs methods has been deprecated and is scheduled to be removed in Gradle 5.0.
- No value has been specified for property 'mainClassName'.
The SimpleWorkResult type has been deprecated and is scheduled to be removed in Gradle …Run Code Online (Sandbox Code Playgroud) 我正在使用 Gradle 5.5。我有一个基于 Groovy 的构建脚本,我正在尝试将其迁移到 Kotlin DSL。该jar任务包含用于将所有依赖项复制到 JAR 文件的典型行:
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
Run Code Online (Sandbox Code Playgroud)
我找不到将这一行转换为 Kotlin DSL 的方法。
让我给你一些背景。这是我最初的基于 Groovy 的构建脚本:
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.41"
}
group = "com.rhubarb_lip_sync"
version = "1.0.0"
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "com.beust:klaxon:5.0.1"
compile "org.apache.commons:commons-lang3:3.9"
compile "no.tornado:tornadofx:1.7.19"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
jar {
manifest {
attributes "Main-Class": "com.rhubarb_lip_sync.rhubarb_for_spine.MainKt"
}
// This line of …Run Code Online (Sandbox Code Playgroud) 在Gradle(5.0+)中有两种创建方法,即任务:
tasks {
val javadocJar by creating(Jar::class) {
val javadoc by tasks
from(javadoc)
classifier = "javadoc"
}
}
Run Code Online (Sandbox Code Playgroud)
和
tasks {
val javadocJar by registering(Jar::class) {
val javadoc by tasks
from(javadoc)
classifier = "javadoc"
}
}
Run Code Online (Sandbox Code Playgroud)
基本上是相同的API,有什么区别?
构建失败:
thufir@dur:~/NetBeansProjects/kotlin_dsl$
thufir@dur:~/NetBeansProjects/kotlin_dsl$ gradle clean run
> Configure project :
e: /home/thufir/NetBeansProjects/kotlin_dsl/build.gradle.kts:4:12: Unresolved reference: github
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'kotlin_dsl'.
> Could not open cache directory 74ykawxta6db3b2bfk9grjikp (/home/thufir/.gradle/caches/4.3.1/gradle-kotlin-dsl/74ykawxta6db3b2bfk9grjikp).
> Internal error: unable to compile script, see log for details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD …Run Code Online (Sandbox Code Playgroud)