Skip to content
Advertisement

Cannot use Apache Commons-IO in Kotlin

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.

Advertisement

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")
}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement