Cannot use Apache Commons-IO in Kotlin

Tags: ,



I’m writing a CLI application, using the default template from IntelliJ IDEA.

I installed commons-io 2.8, by searching for commons-io in the “From Maven” box.

enter image description here

However, IntelliJ can’t find it. For example, I was looking for CountingInputStream, which can be imported by:

import org.apache.commons.io.input.CountingInputStream

But the import fails at .io.

Answer

Your project is seem to be a Gradle one. Gradle based projects can’t add Maven depedencies to their libraries.

Consider adding your library to Gradle build script.

If you use Groovy DSL, add to your build-script the following code (or combine with existing scopes):

repositories {
    mavenCentral()
}

dependencies {
    implementation 'commons-io:commons-io:jar:2.8.0'
}

If you use Kotlin DSL, add to your build-script the following code (or combine with existing scopes):

repositories {
    mavenCentral()
}

dependencies {
    implementation("commons-io:commons-io:jar:2.8.0")
}


Source: stackoverflow