Gradle: Difference between revisions
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
=Setup= | =Setup= | ||
* Ubuntu 20.04 | |||
* Java 14.0.2 | |||
* Kotlin 1.4.0 | |||
* Gradle 6.6 | |||
=Kotlin (JVM)= | |||
Setup was very simple | |||
<syntaxhighlight lang="bash"> | |||
gradle init --type kotlin-application | |||
</syntaxhighlight> | |||
==build.gradle.kts== | |||
This was the output from the above command | |||
<syntaxhighlight lang="bash"> | |||
/* | |||
* This file was generated by the Gradle 'init' task. | |||
* | |||
* This generated file contains a sample Kotlin application project to get you started. | |||
*/ | |||
plugins { | |||
// Apply the Kotlin JVM plugin to add support for Kotlin. | |||
id("org.jetbrains.kotlin.jvm") version "1.3.72" | |||
// Apply the application plugin to add support for building a CLI application. | |||
application | |||
} | |||
repositories { | |||
// Use jcenter for resolving dependencies. | |||
// You can declare any Maven/Ivy/file repository here. | |||
jcenter() | |||
} | |||
dependencies { | |||
// Align versions of all Kotlin components | |||
implementation(platform("org.jetbrains.kotlin:kotlin-bom")) | |||
// Use the Kotlin JDK 8 standard library. | |||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | |||
// Use the Kotlin test library. | |||
testImplementation("org.jetbrains.kotlin:kotlin-test") | |||
// Use the Kotlin JUnit integration. | |||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit") | |||
} | |||
application { | |||
// Define the main class for the application. | |||
mainClassName = "test7.AppKt" | |||
} | |||
</syntaxhighlight> | |||
==File Structure== | |||
<syntaxhighlight lang="bash"> | |||
src | |||
├── main | |||
│ ├── kotlin | |||
│ │ └── test7 | |||
│ │ └── App.kt | |||
│ └── resources | |||
└── test | |||
├── kotlin | |||
│ └── test7 | |||
│ └── AppTest.kt | |||
└── resources | |||
</syntaxhighlight> | |||
=Java= | =Java= | ||
==Project Setup== | ==Project Setup== |
Revision as of 04:24, 22 August 2020
Setup
- Ubuntu 20.04
- Java 14.0.2
- Kotlin 1.4.0
- Gradle 6.6
Kotlin (JVM)
Setup was very simple
gradle init --type kotlin-application
build.gradle.kts
This was the output from the above command
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Kotlin application project to get you started.
*/
plugins {
// Apply the Kotlin JVM plugin to add support for Kotlin.
id("org.jetbrains.kotlin.jvm") version "1.3.72"
// Apply the application plugin to add support for building a CLI application.
application
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// Use the Kotlin test library.
testImplementation("org.jetbrains.kotlin:kotlin-test")
// Use the Kotlin JUnit integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
application {
// Define the main class for the application.
mainClassName = "test7.AppKt"
}
File Structure
src
├── main
│ ├── kotlin
│ │ └── test7
│ │ └── App.kt
│ └── resources
└── test
├── kotlin
│ └── test7
│ └── AppTest.kt
└── resources
Java
Project Setup
mkdir -p test/src/main/java/hello
cd test
touch src/main/java/hello/HelloWorld.java
touch src/main/java/hello/Greeter.java
Source Files
HelloWorld.java
package hello;
import org.joda.time.LocalTime;
public class HelloWorld {
public static void main(String[] args) {
LocalTime currentTime = new LocalTime();
System.out.println("The current local time is: " + currentTime);
Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}
Greeter.java
package hello;
public class Greeter {
public String sayHello() {
return "Hello world!";
}
}
Build File
Create a build.gradle in the project root
apply plugin: 'java'
// Repositories for 3rd parties (nuget repos)
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
// Dependicies (nuget)
dependencies {
compile "joda-time:joda-time:2.2"
testCompile "junit:junit:4.12"
}
// Name of jar to create
jar {
baseName = 'gs-gradle'
version = '0.1.0'
}
Create Gradle Wrapper
This allows others to build it too maybe on winding
gradle wrapper --gradle-version=5.1.1
Run build
./gradlew build