1

I am doing a Spring Boot exercise from Baeldung.com. The project has a test class that uses the method randomAlphabetic, which I have traced back to RandomStringUtils, which in turn belongs to Lang3 from Apache Commons. I can't seem to add the import of RandomStringUtils or even Lang3 itself to my project.

I have looked at the import on the GitHub repository for the project. The project is done as a Maven project, but I have done mine as a Gradle project, because Gradle is what I use at work (I don't know Maven). I have added the following to my build.gradle file:

plugins {
    id 'org.apache.commons'
}
dependencies {
    implementation 'org.apache.commons:commons-lang3:3.12.0'
}

I have attempted the following import statements:

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.*;

When I am writing my import statement and I put the period after commons, the autocomplete only comes up with two choices: logging and logging.impl . I do not even have an option to add lang3. I have also checked in the Spring Initializer to see if I could add lang3 there, but I cannot.

I have downloaded lang3 onto my computer. It contains 5 JAR files plus a lot of other material that I don't know how to use. I thought I could move those JAR files into my Project and External Dependencies 'folder,' but I can't find any way to do so. I'm using Spring Tools 4 Suite for Eclipse, btw.

Any help is appreciated.

apex2022
  • 777
  • 2
  • 8
  • 28
  • Apologies if this is a dumb question, but did you build the project after adding the dependency? – Hopey One Mar 28 '21 at 22:29
  • Did you get any errors when you ran 'gradle build'? – Woodchuck Mar 28 '21 at 22:40
  • FYI, you don't need to manually download the jar, if that's what you're describing. Gradle does that for you. – Woodchuck Mar 28 '21 at 23:16
  • I tried a ./gradlew build but the build failed. * What went wrong: Plugin [id: 'org.apache.commons'] was not found in any of the following sources: - Gradle Core Plugins (plugin is not in 'org.gradle' namespace) - Plugin Repositories (plugin dependency must include a version number for this source) – apex2022 Mar 30 '21 at 19:06
  • Is that the error you got? – Woodchuck Apr 02 '21 at 04:19
  • In general, I believe you first have to do 'gradle init'. Did you do that? I believe that generates a settings.gradle file. Do you have that file in the project? – Woodchuck Apr 02 '21 at 04:22

0 Answers0