简体   繁体   中英

Confused about dependencies in local respository(gradle)

I trying to compile and package up my java application but I am facing issues when trying to specify my local repository in which I have my jars that will be used as dependencies. I have stored all the jars I need for my application in '/home/test/lib'. What I have as my build.gradle file is as follows:

apply plugin:'application'
apply plugin:'java'
apply plugin:'idea'

    def repositoryPath = '/home/test/lib'

    repositories {
        repositoryPath
    }



dependencies {
            "org.springframework:spring-orm:3.0.2.RELEASE"
            "org.springframework:spring-context-support:3.0.2.RELEASE"
            'commons-dbcp:commons-dbcp:1.4'
            'org.apache.ibatis:ibatis-sqlmap:2.3.4.726'
            'commons-dbutils:commons-dbutils:1.3'
            'joda-time:joda-time:1.6'
            'commons-lang:commons-lang:2.5'
            'com.google.collections:google-collections:1.0'
}

jar {
    baseName = 'testJar'
}

mainClassName = "com.some.test.testRunner"

When I run gradle build, I am getting "package * does not exist" errors.

My assumption is that gradle is not finding the requisite external jars in my lib folder. Can somebody point out what I may be doing wrong here.

Thanks

some remarks about your build file. I assume you have a flat directory in '/home/test/lib' that contains your third party libs? If this is the case you can use a flatDir repository, that is declared with the following syntax:

def repositoryPath = '/home/test/lib'

repositories {
    flatDir {
       dirs repositoryPath
    }
}

If /home/test/lib is a ivy repository, you can do:

repositories {
    ivy {
       url repositoryPath
    }
}

This is explained in detail in the Gradle user guide .

in your 'dependencies' section you missed to declare the scope of your dependencies (compile, runtime, etc):

dependencies {
    compile "org.springframework:spring-orm:3.0.2.RELEASE"
    compile "org.springframework:spring-context-support:3.0.2.RELEASE"
    compile 'commons-dbcp:commons-dbcp:1.4'
    compile 'org.apache.ibatis:ibatis-sqlmap:2.3.4.726'
    compile 'commons-dbutils:commons-dbutils:1.3'
    compile 'joda-time:joda-time:1.6'
    compile 'commons-lang:commons-lang:2.5'
    compile 'com.google.collections:google-collections:1.0'
}

if you use a flatdir repository, the group of your dependency definition is often omitted:

dependencies {
    compile ":spring-orm:3.0.2.RELEASE"
    ...
}

Have a look at the gradle user guide for detailed information about dependency handling with gradle: http://gradle.org/docs/current/userguide/userguide_single.html#artifact_dependencies_tutorial

regards, René

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM