0

This is the first time for me to use gradle.

I just typed gradle init and gradle run (I didn't fix any code)

It worked well.

cmd

C:\Users\gksth\eclipse-workspace\myGradle>gradle run

> Task :app:run
Hello World!

BUILD SUCCESSFUL in 6s
15 actionable tasks: 15 executed

But eclipse pops up a message that "The import org apache cannot be resolved"

App.java

package myGradle.app;

import myGradle.list.LinkedList;

import static myGradle.utilities.StringUtils.join;
import static myGradle.utilities.StringUtils.split;
import static myGradle.app.MessageUtils.getMessage;

import org.apache.commons.text.WordUtils;

public class App {
    public static void main(String[] args) {
        LinkedList tokens;
        tokens = split(getMessage());
        String result = join(tokens);
        System.out.println(WordUtils.capitalize(result));
    }
}

build.gradle

plugins {
    id 'myGradle.java-application-conventions'
}

dependencies {
    implementation 'org.apache.commons:commons-text'
    implementation project(':utilities')
}

application {
    // Define the main class for the application.
    mainClass = 'myGradle.app.App'
}

How can I fix it?

onepine
  • 1
  • 2
  • https://stackoverflow.com/questions/14609722/the-import-org-apache-commons-cannot-be-resolved-in-eclipse-juno/26856464 may be this link will be helpful for you – SYED MUSTAFA HUSSAIN Aug 09 '21 at 11:45

1 Answers1

0

Add this in the dependencies

dependencies {  
    // https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'  

}
  • I did in the build.gradle dependencies. and the result: FAILURE: Build failed with an exception. * Where: Build file 'C:\Users\gksth\eclipse-workspace\myGradle\app\build.gradle' line: 11 * What went wrong: A problem occurred evaluating project ':app'. > Could not find method compile() for arguments [{group=org.apache.commons, name=commons-lang3, version=3.9}] on obje ct of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. – onepine Aug 09 '21 at 12:19
  • https://stackoverflow.com/questions/14609722/the-import-org-apache-commons-cannot-be-resolved-in-eclipse-juno/26856464 try this – SYED MUSTAFA HUSSAIN Aug 09 '21 at 13:02
  • Thanks but.. is this the best? With gradle, should I download jar file and put it in right path myself? – onepine Aug 09 '21 at 15:12
  • I think so add dependencies in Gradle is the best choice instead of adding a manual jar file Because when you send the project then he will also add a manual jar file. – SYED MUSTAFA HUSSAIN Aug 09 '21 at 15:40