Cant import packages to gradle build file


(Alexei Sakharov) #1

Can’t to import apache commons-lang to gradle build file. It worked well in gradle-milestone-3, but not in milestone-4 - milestone-8.

build.gradle

import org.apache.commons.lang.SystemUtils

apply plugin: ‘eclipse’

mainVersion = ‘1.0-SNAPSHOT’

orgSpringframeworkVersion = ‘3.1.0.RELEASE’

allprojects {

repositories {

mavenLocal()

mavenCentral()

} }

libraries = [

commonsLang: ‘commons-lang:commons-lang:2.6’, ]

dependencies {

compile( libraries.commonsLang ) } …

Could not compile build file ‘build.gradle’. > startup failed:

build file ‘build.gradle’: 1: unable to resolve class org.apache.commons.lang.SystemUtils

@ line 1, column 1.

import org.apache.commons.lang.SystemUtils


(Adam Murdoch) #2

This was working by coincidence in 1.0-milestone-3, as the build script class path used to include all the jars in the Gradle distribution’s lib/ directory, which happened to include commons-lang. From 1.0-milestone-4 onwards, these jars are no longer included in the build script class path. Have a look at the migration guide for more details.

To fix this, you need to declare that your build script needs commons-lang, something like:

buildscript {
    repositories { mavenCentral() }
    dependencies { classpath 'commons-lang:commons-lang:2.6' }
}