Skip to content

Commit 8a330a5

Browse files
committed
Convert Kotlin example to Gradle
1 parent ccaa375 commit 8a330a5

15 files changed

Lines changed: 404 additions & 643 deletions

File tree

examples/enumerate_kotlin/.gitignore

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
target/
2-
!.mvn/wrapper/maven-wrapper.jar
3-
!**/src/main/**/target/
4-
!**/src/test/**/target/
1+
.gradle
2+
build/
3+
!gradle/wrapper/gradle-wrapper.jar
4+
!**/src/main/**/build/
5+
!**/src/test/**/build/
56

67
### IntelliJ IDEA ###
78
.idea/modules.xml
@@ -11,6 +12,12 @@ target/
1112
*.iws
1213
*.iml
1314
*.ipr
15+
out/
16+
!**/src/main/**/out/
17+
!**/src/test/**/out/
18+
19+
### Kotlin ###
20+
.kotlin
1421

1522
### Eclipse ###
1623
.apt_generated
@@ -20,16 +27,16 @@ target/
2027
.settings
2128
.springBeans
2229
.sts4-cache
30+
bin/
31+
!**/src/main/**/bin/
32+
!**/src/test/**/bin/
2333

2434
### NetBeans ###
2535
/nbproject/private/
2636
/nbbuild/
2737
/dist/
2838
/nbdist/
2939
/.nb-gradle/
30-
build/
31-
!**/src/main/**/build/
32-
!**/src/test/**/build/
3340

3441
### VS Code ###
3542
.vscode/
-61.1 KB
Binary file not shown.

examples/enumerate_kotlin/.mvn/wrapper/maven-wrapper.properties

Lines changed: 0 additions & 18 deletions
This file was deleted.

examples/enumerate_kotlin/README.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ This sample enumerates the connected USB devices and provides information about
44

55
## Prerequisites
66

7-
- Java 22
8-
- Apache Maven
7+
- Java 25
8+
- Gradle
99
- 64-bit operating system (Windows, macOS, Linux)
1010

1111
## How to run
1212

13-
### Install Java 22 or higher
13+
### Install Java 25 or higher
1414

15-
Check that Java 22 or higher is installed:
15+
Check that Java 25 or higher is installed:
1616

1717
```shell
1818
$ java -version
@@ -25,22 +25,16 @@ If not, download and install it, e.g. from [Azul](https://www.azul.com/downloads
2525
Check that *Maven* is installed:
2626

2727
```shell
28-
$ mvn -version
28+
$ gradle -version
2929
```
3030

3131
If it is not present, install it, typically using package manager like *Homebrew* on macOS, *Chocolately* on Windows and *apt* on Linux.
3232

33-
### Build a self-contained jar file
33+
### Build and run the program
3434

3535
```shell
3636
$ cd JavaDoesUSB/examples/enumerate_kotlin
37-
$ mvn clean package
38-
```
39-
40-
### Run the jar
41-
42-
```shell
43-
$ java --enable-native-access=ALL-UNNAMED -jar target/enumerate-1.2.1-jar-with-dependencies.jar
37+
$ gradle run
4438
Device:
4539
VID: 0xcafe
4640
PID: 0xceaf
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
plugins {
2+
kotlin("jvm") version "2.3.21"
3+
application
4+
}
5+
6+
group = "net.codecrete.usb.examples"
7+
version = "1.2.1"
8+
9+
val javaDoesUsbVersion = "1.2.1"
10+
val tinyLogVersion = "2.7.0"
11+
12+
repositories {
13+
mavenLocal()
14+
mavenCentral()
15+
}
16+
17+
dependencies {
18+
implementation("net.codecrete.usb:java-does-usb:$javaDoesUsbVersion")
19+
implementation("org.tinylog:tinylog-api:$tinyLogVersion")
20+
implementation("org.tinylog:tinylog-impl:$tinyLogVersion")
21+
implementation("org.tinylog:jsl-tinylog:$tinyLogVersion")
22+
23+
testImplementation(kotlin("test"))
24+
}
25+
26+
kotlin {
27+
jvmToolchain(25)
28+
}
29+
30+
application {
31+
mainClass = "net.codecrete.usb.examples.EnumerateKt"
32+
applicationDefaultJvmArgs = listOf("--enable-native-access=ALL-UNNAMED")
33+
}
34+
35+
tasks.test {
36+
useJUnitPlatform()
37+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
kotlin.code.style=official
2+
org.gradle.configuration-cache=true
47.3 KB
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
4+
networkTimeout=10000
5+
retries=0
6+
retryBackOffMs=500
7+
validateDistributionUrl=true
8+
zipStoreBase=GRADLE_USER_HOME
9+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)