简体   繁体   English

对本地存储库中的依赖项感到困惑(等级)

[英]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. 我试图编译和打包Java应用程序,但是在尝试指定本地存储库(其中将我的jar用作依赖项)时遇到了问题。 I have stored all the jars I need for my application in '/home/test/lib'. 我已经将我的应用程序所需的所有jar保存在“ / home / test / lib”中。 What I have as my build.gradle file is as follows: 我的build.gradle文件如下所示:

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. 当我运行gradle build时,出现“包*不存在”错误。

My assumption is that gradle is not finding the requisite external jars in my lib folder. 我的假设是gradle在我的lib文件夹中找不到必需的外部jar。 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? 我假设您在'/ home / test / lib'中有一个平面目录,其中包含您的第三方库? If this is the case you can use a flatDir repository, that is declared with the following syntax: 如果是这种情况,则可以使用flatDir存储库,该存储库使用以下语法声明:

def repositoryPath = '/home/test/lib'

repositories {
    flatDir {
       dirs repositoryPath
    }
}

If /home/test/lib is a ivy repository, you can do: 如果/ home / test / lib是一个常春藤存储库,则可以执行以下操作:

repositories {
    ivy {
       url repositoryPath
    }
}

This is explained in detail in the Gradle user guide . Gradle用户指南中对此进行了详细说明。

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: 如果使用flatdir存储库,则通常会省略依赖项定义的组:

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 请参阅gradle用户指南,以获取有关使用gradle处理依赖关系的详细信息: http ://gradle.org/docs/current/userguide/userguide_single.html#artifact_dependencies_tutorial

regards, René 问候,雷内

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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