0

tl;博士; 向 build.gradle 添加添加依赖项可以很好地下载它,但不会将其添加到想法中的类路径/外部库中。

嗨,大家好

我是使用 java 开发 webapps 的新手,我试图依赖 mvnrepository.com 上的一些 jar,唯一一次将依赖项下载到外部库并添加到类路径中是当我将项目作为 gradle 项目导入时,如在,每次我有一个项目启动并运行并且我添加一个新的依赖项时,我都必须再次将整个项目导入到 intellij 中。

我的 build.gradle 文件如下所示:

group 'project_name'
version '1.0-SNAPSHOT'

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

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
// https://mvnrepository.com/artifact/com.google.inject/guice
 compile group: 'com.google.inject', name: 'guice', version: '3.0'
// https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core
 compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '9.0.0.M9'
// https://mvnrepository.com/artifact/com.sun.jersey/jersey-core
 compile group: 'com.sun.jersey', name: 'jersey-core', version: '1.19.1'
// https://mvnrepository.com/artifact/com.sun.jersey/jersey-json
 compile group: 'com.sun.jersey', name: 'jersey-json', version: '1.19.1'

// https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client
 compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.23.2'

// https://mvnrepository.com/artifact/com.sun.jersey/jersey-servlet
 compile group: 'com.sun.jersey', name: 'jersey-servlet', version: '1.19.1'

// https://mvnrepository.com/artifact/com.sun.jersey/jersey-server
 compile group: 'com.sun.jersey', name: 'jersey-server', version: '1.19.1'




 testCompile group: 'junit', name: 'junit', version: '4.11'
}



task wrapper(type: Wrapper) {
    gradleVersion = '2.5'
}

当我向列表中添加新的依赖项并运行 ./gradlew build 时,无论是否使用 --refresh-dependencies 选项,它都会下载新的依赖项,但不会将下载的文件添加到外部库/类路径中,所以我无法将它们导入java代码。我看到了一个与此类似的问题,他们接受了诸如跑步之类的答案:

./gradlew idea

就我而言,这根本没有帮助,它只是在目录中添加了一些自动生成的文件,而行为没有明显区别。

然后他们也接受了将项目作为 gradle 项目导入,我已经这样做了——这可行,但添加新的依赖项不起作用。

仅供参考,我正在使用 gradle 2.5 包装器和 IDEA 社区 16.2

4

1 回答 1

2

好的。我解决了/想通了,显然运行构建并没有帮助,在intellij内部我必须转到查看->工具窗口-> Gradle,然后打开gradle窗口,我可以在其中单击刷新按钮,用于下载依赖项。

感谢任何看过它的人:)

于 2016-08-22T15:07:30.337 回答