Could not resolve commons-codec:commons-codec:1.6


(Rajendra Rawat) #1

Hello,

I am new to Gradle and am facing below error message during build.
content of my build.gradle file is:


apply plugin: ‘java’

repositories {
mavenCentral()
}

dependencies {
compile ‘commons-codec:commons-codec:1.6’
}

task caesar(type: JavaExec) {
main = 'org.gradle.poetry.Poetry’
classpath = sourceSets.main.runtimeClasspath
}

.java file to be built.


package org.gradle.poetry;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.codec.binary.base64;

public class Poetry{
public List juliusCaesar(){
List lines=new ArrayList();
lines.add(“abd, efg”);
lines.add(“xyz”);
lines.add(“123”);
lines.add(“234”);
lines.add(“345”);
lines.add(“456”);
lines.add(“567”);
lines.add(“678”);
lines.add(“789”);
lines.add(“1bc”);
lines.add(“bcd”);
return lines;
}
public void emit(List lines)
{
for(String line:lines)
{
System.out.println(encode(line));
}
}
public String encode(String text){
Base64 codec=new Base64();
return new String(codec.encode(text.getByte()));

    }
    public static void main(String args[]){
            Poetry p=new Poetry();
            p.emit(p.juliusCaesar());

    }

}

Run goes here
xyzserver$ gradle caesar
:compileJava

FAILURE: Build failed with an exception.

What went wrong:
Could not resolve all dependencies for configuration ‘:compileClasspath’.

Could not resolve commons-codec:commons-codec:1.6.
Required by:
:poetry:unspecified
Could not resolve commons-codec:commons-codec:1.6.
Could not get resource ‘https://repo1.maven.org/maven2/commons-codec/commons-codec/1.6/commons-codec-1.6.pom’.
Could not HEAD ‘https://repo1.maven.org/maven2/commons-codec/commons-codec/1.6/commons-codec-1.6.pom’.
No route to host

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 44.687 secs

Please help solve this issue. it something missing here?


(René Groeschke) #2

It seems like you’re running your build behind a proxy and don’t have
direct access to maven central. If that’s the case you need to set your
proxy settings accordingly for the gradle build.

Consult the according chapter in the userguide to find out how to do
this: https://docs.gradle.org/current/userguide/userguide_single.html#N109F2


(Rajendra Rawat) #3

Hi Rene,

You are genius.
It is working fine after making changes to proxy settings as you suggested.
Thanks a lot for helping me resolve this issue.