我已经编写了一个简单的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新手.我想构建一个uberjar(AKA fatjar),它包含项目的所有传递依赖项.我需要在"build.gradle"中添加哪些行?
这就是我现在所拥有的:(我几天前从某处复制过,但不记得从哪里开始.)
task uberjar(type: Jar) {
from files(sourceSets.main.output.classesDir)
manifest {
attributes 'Implementation-Title': 'Foobar',
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Main-Class': mainClassName
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用kotlin和gradle,但我无法使用Intellij Idea 15成功创建项目.
我已经创建了有两个模块简单的项目hello-java和hello-kotlin.
hello-java 是普通的java项目,它正在编译和运行完美.
hello-kotlin是简单的kotin模块,只有一个*.kt文件和build.gradle文件.
以下是来源:
的build.gradle
group 'pl.fzymek.kotlin'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:0.10.4"
}
}
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = 'HelloKotlinKt'
repositories {
mavenCentral()
}
jar {
manifest {
attributes 'Main-Class': mainClassName
}
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:0.10.4"
}
Run Code Online (Sandbox Code Playgroud)
HelloKotlin.kt
fun main(args: Array<String>) {
println("Hello, Kotlin!")
}
Run Code Online (Sandbox Code Playgroud)
主模块settings.gradle
include 'hello-java'
include 'hello-kotlin'
Run Code Online (Sandbox Code Playgroud)
运行时gradlew clean build所有项目都编译成功,但运行时出现java -jar hello-kotlin-1.0-SNAPSHOT.jar …
我想创建使用一个简单的HelloWorld应用程序kotlin,gradle该gradle这个和application插件.当我使用以下设置运行它时,我收到以下错误:
Error: Main method is not static in class com.petarkolaric.helloworld.Main, please define the main method as:
public static void main(String[] args)
Run Code Online (Sandbox Code Playgroud)
我的build.gradle:
group 'helloworld'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.2.0'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = "com.petarkolaric.helloworld.Main"
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Run Code Online (Sandbox Code Playgroud)
我的 …