Issue
I'd like to generate some uuid4s with Kotlin. I use Maven to manage my project, and I'm actually quite new to both Kotlin and Maven.
I see there's a Kotlin library named com.benasher44.uuid
that should do what I want.
I found the dependency snippet on href="https://mvnrepository.com" rel="nofollow noreferrer">https://mvnrepository.com and I added it to the dependencies in my pom.xml:
<dependencies>
...
<dependency>
<groupId>com.benasher44</groupId>
<artifactId>uuid</artifactId>
<version>0.2.3</version>
</dependency>
</dependencies>
I put:
import com.benasher44.uuid.uuid4
at the beginning of my Kotlin .tk source file (I've seen on Github that this is how some people use the package). But when I do:
mvn clean test
I get the error:
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.4.31:test-compile (test-compile) on project my-project: Compilation failure: Compilation failure:
[ERROR] /home/username/my-directory/my-project/src/test/kotlin/com/mydomain/mypackage/MyTest.kt:[4,28] Unresolved reference: uuid4
I also tried some other commands such as mvn dependency:resolve
mvn install
, mvn clean install -U
but that doesn't solve the problem. What should I do to be able to use this package?
Solution
The dependency you are trying to include in your Maven project is for Kotlin Multiplatform and Multiplatform is not yet supported with Maven.
Use the following dependency which works for JVM.
<dependencies>
<dependency>
<groupId>com.benasher44</groupId>
<artifactId>uuid-jvm</artifactId>
<version>0.2.3</version>
</dependency>
</dependencies>
Answered By - Nicodemus Ojwee
Answer Checked By - Senaida (JavaFixing Volunteer)