gpt4 book ai didi

Gradle 将本地 jar 复制到缓存中

转载 作者:行者123 更新时间:2023-12-03 03:59:03 25 4
gpt4 key购买 nike

我需要一些帮助来理解为什么我的 build.gradle 不会将本地引用的 jar 复制到它的缓存中。在 Windows 上,我希望在 C:\Users\myusername .gradle 中看到 jar,并且确实存在其他 JAR。

我无法在 IntelliJ 中导入此 JAR,因为它找不到它。

附带问题:有人知道如何调试 Gradle 的 DSL 吗?我设置了远程调试,而 IntelliJ 从未达到我的断点。它上面没有复选框,所以我猜 IDE 不认为它是代码。

有几件事对我来说没有意义:

 1. gradle dependencies --configuration compile

\--- com.google.guava:guava:23.5-jre
+--- com.google.code.findbugs:jsr305:1.3.9
....

MY_JAR_1.0.1.jar is not present.

2. gradle copyDependencies - this task finds and copies it.
task copyDependencies(type: Copy) {
from configurations.compile
into 'dependencies'
}

3. This task also finds my jar.
task listcompile << {
configurations.compile.each { File file -> println file.name }
}

Why does #1 not find it?

apply plugin: 'java'

repositories {
mavenCentral()
//flatDir {
// dirs 'customlibs'
//}
}

dependencies {
compile group: 'com.google.guava', name: 'guava', version: '23.5-jre'
compile files('customlibs/MY_JAR_1.0.1.jar')
}

task listcompile << {
configurations.compile.each { File file -> println file.name }
}

// copy all dependencies into this folder
task copyDependencies(type: Copy) {
from configurations.compile
into 'dependencies'
}

最佳答案

看来Gradle的dependencies任务将仅显示具有已定义 group:name:version 坐标的模块。您正在直接添加一个文件,没有关联的标识符。

您可以做的是添加一个平面目录存储库并将您的自定义 JAR 声明为普通依赖项,如下所示:

repositories {
flatDir {
dirs 'customlibs'
}
}

dependencies {
compile ':MY_JAR:1.0.1'
}

您需要重命名 JAR 以使其符合 Maven/Gradle 的命名约定,即 MY_NAME-1.0.1.jar(用连字符替换最后一个下划线)。

关于Gradle 将本地 jar 复制到缓存中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49969803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com