gpt4 book ai didi

java - 从远程服务器访问依赖项

转载 作者:行者123 更新时间:2023-12-01 06:04:26 25 4
gpt4 key购买 nike

我在 gitlab 存储库中托管了一个依赖项,我正尝试在另一个项目中访问该依赖项。我已经在另一个项目的根 build.gradle 中提供了我的存储库的路径,但是由于某种原因,由 gradle 生成的用于获取依赖项的 URL 无效。我一直在试图找出我可能做错了什么,但到目前为止我无法指出问题所在。

我发布了用于生成 aar 文件的 gradle 代码以及尝试在另一个 Android 应用程序中获取此依赖项的代码。

库build.gradle文件:

publishing {
publications {
maven(MavenPublication) {
groupId 'com.umer' //You can either define these here or get them from project conf elsewhere
artifactId 'myLibrary'
version project.version
artifact "$buildDir/outputs/aar/myLibrary-release.aar" //aar artifact you want to publish

//generate pom nodes for dependencies
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.compile.allDependencies.each { dependency ->
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dependency.group)
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
}
}
}
}

//publish to filesystem repo
repositories{
maven {
url "C:\\Users\\Umer\\AndroidStudioProjects\\android\\myLibrary\\artifacts"
}
}
}

Android应用程序的应用程序级别build.gradle:

dependencies {
provided ('com.umer.myLibrary:myLibrary-1.1')
}

Android 应用根目录 build.gradle:

buildscript {

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
maven {
url 'http:/GIT_LAB_IP_ADDRESS/dev/myLibrary/tree/BRANCH_NAME/artifacts'
credentials {
username = "myUserName"
password = "myPassword"
}
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

Android应用程序的gradle.properties:

systemProp.http.proxyHost=127.0.0.1
systemProp.https.proxyPort=12345
org.gradle.jvmargs=-Xmx1536m
systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=12345

Android 应用项目中的 Gradle 同步错误:

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.umer.myLibrary:myLibrary-1.1:.

Could not resolve com.umer.myLibrary:myLibrary-1.1:.
Required by:
project :app
> Could not resolve com.umer.myLibrary:myLibrary-1.1:.
> Could not get resource 'http://GIT_LAB_IP_ADDRESS/dev/myLibrary/tree/remoteRepoPublication/artifacts/com/umer/myLibrary/myLibrary-1.1//myLibrary-1.1-.pom'.
> Could not HEAD 'http://GIT_LAB_IP_ADDRESS/dev/myLibrary/tree/remoteRepoPublication/artifacts/com/umer/myLibrary/myLibrary-1.1//myLibrary-1.1-.pom'.
> Connect to 127.0.0.1:12345 [/127.0.0.1] failed: Connection refused: connect
> Connection refused: connect

如何修复它?

PS:

这是 Android 应用中 Gradle 生成的格式错误的 URL。

http://GIT_LAB_IP_ADDRESS/dev/myLibrary/tree/remoteRepoPublication/artifacts/com/umer/myLibrary/myLibrary-1.1//myLibrary-1.1-.pom

最佳答案

通过查看格式错误的网址:'http://GIT_LAB_IP_ADDRESS/dev/myLibrary/tree/remoteRepoPublication/artifacts/com/umer/myLibrary/myLibrary-1.1//myLibrary-1.1-.pom '

您似乎有两个问题:1.需要将GIT_LAB_IP_ADDRESS替换为真实主机名/ip。为此,您可以使用双引号和 $ 符号作为占位符:

“http://${GIT_LAB_IP_ADDRESS}/dev/myLibrary/tree/remoteRepoPublication/artifacts/com/umer/myLibrary/myLibrary-1.1//myLibrary-1.1-.pom”

其中 GIT_LAB_IP_ADDRESS 要么从 local.properties 加载,要么在 build.gradle 文件中定义。

  • 看起来您的网址中还有另一个//,就在最后一部分之前(除非是拼写错误)
  • 希望这有帮助。

    关于java - 从远程服务器访问依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47813265/

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