【问题标题】:Accessing dependency from Remote Server从远程服务器访问依赖项
【发布时间】:2017-12-14 12:21:49
【问题描述】:

我在我的 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 App 的App Level 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:

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

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

【问题讨论】:

  • 有关如何解决此问题的任何指示?

标签: java android maven build.gradle


【解决方案1】:

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

您似乎有 2 个问题: 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 文件中定义。

  1. 您的网址中似乎有另一个 // 在最后一部分之前(除非是拼写错误)

希望这会有所帮助。

【讨论】:

  • 我知道。它只是这里问题的占位符。在我的项目中,这被真实的ip所取代
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-21
相关资源
最近更新 更多