3

I'm writing a Java program - a plain command line program, not Android or anything like that - using Gradle, and trying to include Apache Commons IO. Per https://mvnrepository.com/artifact/commons-io/commons-io/2.6 I ended up with build.gradle like this:

apply plugin: 'application' apply plugin: 'java' repositories { mavenCentral() } dependencies { // https://mvnrepository.com/artifact/commons-io/commons-io compile group: 'commons-io', name: 'commons-io', version: '2.6' } mainClassName = 'Main' 

Gradle seems to download the package happily enough, but import statements referring to apache or commons get a not found error; this is true even when I run gradle build from the command line, omitting any IDE. What am I missing? (Previous similar discussions have been for Android or Eclipse projects; the instructions for those haven't worked here.)

1 Answer 1

2

I don't see any problems with your Gradle script, so at first glance, I'm thinking of two possible explanations:

  • you import a class that cannot be found in the artifact (e.g. a previous version of commons-io deprecated it and now they removed it)
  • your project's structure is set up incorrectly

I copied the exact contents of your script in a build.gradle file, created a src/main/java directory structure in the same directory, and wrote a small application Main.java under that directory with the following:

import org.apache.commons.io.IOCase; public class Main { public static void main(String[] args) { System.out.println(IOCase.SENSITIVE.checkEndsWith("abcd1234", "1234")); } } 

The code compiles successfully, so I need more context to troubleshoot your problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Tried your test case and it worked, went back to my project and it works, so I don't know what was going wrong before, maybe something hadn't saved/updated? But it works now, thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.