问题。
分级依赖项管理是这样进行的:
configurations {
download
testDownload
}
task cleanDownloadedDependencies(type: Delete) {
delete fileTree('libs/compile/downloaded')
}
task cleanDownloadedTestDependencies(type: Delete) {
delete fileTree('libs/testCompile/downloaded')
}
task downloadDependencies(type: Copy) {
from configurations.download
into "libs/compile/downloaded/"
}
从testdownload
配置下载依赖项:
task downloadTestDependencies(type: Copy) {
from configurations.testDownload
into "libs/testCompile/downloaded/"
}
执行以上所有任务以更新依赖项:
task updateDependencies {
dependsOn cleanDownloadedDependencies, cleanDownloadedTestDependencies, downloadDependencies, downloadTestDependencies
}
接下来我们定义我们的依赖关系:
dependencies {
download(
'com.google.code.gson:gson:+',
'joda-time:joda-time:+',
)
testDownload(
'junit:junit:+'
)
compile fileTree(dir: 'libs/compile', include: '**/*.jar')
testCompile fileTree(dir: 'libs/testCompile', include: '**/*.jar')
}
./gradlew updateDependencies
...
repositories {
...
flatDir {
dirs 'libs/compile', 'libs/compile/downloaded',
'libs/testCompile', 'libs/testCompileDownloaded',
'libs/androidTestCompile', 'libs/androidTestCompile/downloaded'
}
}
configurations {
download
testDownload
androidTestDownload
}
android {
...
}
dependencies {
download(
'com.android.support:support-v4:+',
'com.android.support:appcompat-v7:+',
'com.google.android.gms:play-services-location:+',
'com.facebook.android:facebook-android-sdk:+',
'com.vk:androidsdk:+',
'com.crashlytics.sdk.android:crashlytics:+',
'oauth.signpost:signpost-core:+',
'oauth.signpost:signpost-commonshttp4:+',
'org.twitter4j:twitter4j-core:+',
'commons-io:commons-io:+',
'com.google.code.gson:gson:+',
'org.jdeferred:jdeferred-android-aar:+'
)
compile fileTree(dir: 'libs/compile', include: '**/*.jar')
testCompile fileTree(dir: 'libs/testCompile', include: '**/*.jar')
androidTestCompile fileTree(dir: 'libs/androidTestCompile', include: '**/*.jar')
}
task cleanDownloadedDependencies(type: Delete) {
delete fileTree('libs/compile/downloaded')
}
task cleanDownloadedTestDependencies(type: Delete) {
delete fileTree('libs/testCompile/downloaded')
}
task cleanDownloadedAndroidTestDependencies(type: Delete) {
delete fileTree('libs/androidTestCompile/downloaded')
}
task downloadDependencies(type: Copy) {
from configurations.download
into 'libs/compile/downloaded/'
}
task downloadTestDependencies(type: Copy) {
from configurations.testDownload
into 'libs/testCompile/downloaded/'
}
task downloadAndroidTestDependencies(type: Copy) {
from configurations.androidTestDownload
into 'libs/androidTestCompile/downloaded/'
}
task updateDependencies {
dependsOn cleanDownloadedDependencies, cleanDownloadedTestDependencies, cleanDownloadedAndroidTestDependencies, downloadDependencies, downloadTestDependencies, downloadAndroidTestDependencies
}
fileTree(dir: 'libs/compile', include: '**/*.aar')
.each { File file ->
dependencies.add("compile",
[name: file.name.lastIndexOf('.').with { it != -1 ? file.name[0..<it] : file.name }, ext: 'aar'])
}
fileTree(dir: 'libs/testCompile', include: '**/*.aar')
.each { File file ->
dependencies.add("testCompile",
[name: file.name.lastIndexOf('.').with { it != -1 ? file.name[0..<it] : file.name }, ext: 'aar'])
}
fileTree(dir: 'libs/androidTestCompile', include: '**/*.aar')
.each { File file ->
dependencies.add("androidTestCompile",
[name: file.name.lastIndexOf('.').with { it != -1 ? file.name[0..<it] : file.name }, ext: 'aar'])
}
问题内容: 问题。 Gradle依赖管理使得: 没有简便的方法来检查依赖项更新的可用性(仅使用某些第三方插件,如ben-manes / gradle-versions-plugin)并下载更新以替换旧版本; 从远程存储库下载依赖项工件,然后将其存储在gradle缓存中,并在后续构建中重用;但是项目的成功编译必须不依赖于与Internet的连接,远程存储库的可用性以及这些存储库中特定版本的依赖项。
MVNRepository通常为每个依赖项列出“版本”和“更新”。 如果我发布自己的包,如何指定“更新”版本 Maven在解决传递依赖时使用了哪个依赖项?所以如果我的包依赖于包A,它依赖于包B,版本=1.0,更新=1.1。我会得到哪个版本的B?
我正在尝试添加以下依赖项:
告诉Gradle以下内容的最简单方法是什么: 检索“junit”依赖项并获取其最新版本。 管理Maven和Ivy仓库对我来说有点新鲜。我尝试了以下步骤,它们导致错误: > 编写,并按以下方式设置存储库: 尝试使用Spring Source Ivy仓库: 也许我误解了什么。为什么获取最新版本的依赖项会如此困难?
我用我的真实情况来说明问题。 我使用logback 1.0.1进行日志记录,它包含SLF4J 1.6.4作为依赖项。我还为遗留日志API(Java . util . logging、log4j和commons-logging)使用SLF4J API桥,它们不是显式的依赖关系。这些也必须(最好)是版本1.6.4。 为了使我的pom.xml尽可能整洁和无错误,我想强制这些API桥接器与SLF4J版本相