Gradle:移动到多项目结构-无法解析存储库

Gradle:移动到多项目结构-无法解析存储库,gradle,build.gradle,artifactory,gradlew,Gradle,Build.gradle,Artifactory,Gradlew,我有一个项目,它依赖于本地artifactory来实现几个依赖项 此项目上的Gradle build运行良好,存储库设置正确: buildscript { repositories { maven { url "${artifactoryUrl}/libs-release" } } dependencies { classpath 'org.jfrog.buildinfo:build-info-ext

我有一个项目,它依赖于本地artifactory来实现几个依赖项

此项目上的Gradle build运行良好,存储库设置正确:

buildscript {
    repositories {
        maven {
            url "${artifactoryUrl}/libs-release"
        }
    }
    dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.4.10'
   }
}

repositories {
    maven {
        url "${artifactoryUrl}/repo"
    }
}

artifactory {
    contextUrl = "${artifactoryUrl}"
    publish {
        repository {
            repoKey = 'libs-snapshot-local' // The Artifactory repository key to publish to
            username = "${artifactoryUser}" // The publisher user name
            password = "${artifactoryPassword}" // The publisher password
        }
        defaults {
            // Reference to Gradle publications defined in the build script.
            // This is how we tell the Artifactory Plugin which artifacts should be
            // published to Artifactory.
            publications('mavenJava')
            publishArtifacts = true
            // Properties to be attached to the published artifacts.
            properties = ['qa.level': 'basic', 'dev.team' : 'core']
        }
    }
    resolve {
        repoKey = 'repo'
    }
}
我学习了gradle关于多项目结构的教程。看起来我可以将“repository”部分移动到根
gradle.build
文件中。但是,当我运行gradle build时,我从artifactory获得了所有依赖项的错误信息:

无法解析外部依赖关系

注意:我还在根目录中添加了
gradle.properties
文件,其中包含所有变量(artifactoryUrl等)

因此,子项目似乎无法“查看”根
gradle.build
文件中定义的存储库。有什么建议吗

更新

我的根目录上的
build.gradle
现在如下所示:

allprojects {
}

subprojects {
    buildscript {
        repositories {
            maven {
                url "${artifactoryUrl}/libs-release"
            }
        }
        dependencies {
            classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.4.10'
       }
    }

    repositories {
        maven {
            url "${artifactoryUrl}/repo"
        }
    }

    artifactory {
        contextUrl = "${artifactoryUrl}"
        publish {
            repository {
                repoKey = 'libs-snapshot-local' // The Artifactory repository key to publish to
                username = "${artifactoryUser}" // The publisher user name
                password = "${artifactoryPassword}" // The publisher password
            }
            defaults {
                // Reference to Gradle publications defined in the build script.
                // This is how we tell the Artifactory Plugin which artifacts should be
                // published to Artifactory.
                publications('mavenJava')
                publishArtifacts = true
                // Properties to be attached to the published artifacts.
                properties = ['qa.level': 'basic', 'dev.team' : 'core']
            }
        }
        resolve {
            repoKey = 'repo'
        }
    }
}

您需要将
存储库
(和
人工制品
)块放入
子项目
所有项目
块中。因此:

subprojects {
  repositories {
    maven {
        url "${artifactoryUrl}/repo"
    }
  }
  ...
}
这将确保根
build.gradle
将配置下推到每个子项目的配置中

同样对于artifactory,不要忘记将artifactory插件应用于所有子项目:

subprojects {
  apply plugin: "com.jfrog.artifactory"

  ...
}

您需要将
存储库
(和
人工制品
)块放入
子项目
所有项目
块中。因此:

subprojects {
  repositories {
    maven {
        url "${artifactoryUrl}/repo"
    }
  }
  ...
}
这将确保根
build.gradle
将配置下推到每个子项目的配置中

同样对于artifactory,不要忘记将artifactory插件应用于所有子项目:

subprojects {
  apply plugin: "com.jfrog.artifactory"

  ...
}

因此,在看了一些示例之后,我意识到
buildscript
部分应该在
子项目
部分之外,而不是内部。而且
apply插件:“com.jfrog.artifactory”
也应该添加到subprojects部分中

buildscript {
    repositories {
        maven {
            url "${artifactoryUrl}/libs-release"
        }
    }
    dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.4.10'
   }
}

subprojects {
    repositories {
        maven {
            url "${artifactoryUrl}/repo"
        }
    }

    artifactory {
        contextUrl = "${artifactoryUrl}"
        publish {
            repository {
                repoKey = 'libs-snapshot-local' // The Artifactory repository key to publish to
                username = "${artifactoryUser}" // The publisher user name
                password = "${artifactoryPassword}" // The publisher password
            }
        defaults {
                // Reference to Gradle publications defined in the build script.
                // This is how we tell the Artifactory Plugin which artifacts should be
                // published to Artifactory.
                publications('mavenJava')
                publishArtifacts = true
                // Properties to be attached to the published artifacts.
                properties = ['qa.level': 'basic', 'dev.team' : 'core']
            }
        }
        resolve {
            repoKey = 'repo'
        }
    }
}

因此,在看了一些示例之后,我意识到
buildscript
部分应该在
子项目
部分之外,而不是内部。而且
apply插件:“com.jfrog.artifactory”
也应该添加到subprojects部分中

buildscript {
    repositories {
        maven {
            url "${artifactoryUrl}/libs-release"
        }
    }
    dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.4.10'
   }
}

subprojects {
    repositories {
        maven {
            url "${artifactoryUrl}/repo"
        }
    }

    artifactory {
        contextUrl = "${artifactoryUrl}"
        publish {
            repository {
                repoKey = 'libs-snapshot-local' // The Artifactory repository key to publish to
                username = "${artifactoryUser}" // The publisher user name
                password = "${artifactoryPassword}" // The publisher password
            }
        defaults {
                // Reference to Gradle publications defined in the build script.
                // This is how we tell the Artifactory Plugin which artifacts should be
                // published to Artifactory.
                publications('mavenJava')
                publishArtifacts = true
                // Properties to be attached to the published artifacts.
                properties = ['qa.level': 'basic', 'dev.team' : 'core']
            }
        }
        resolve {
            repoKey = 'repo'
        }
    }
}

是的。使用完整的root build.gradle文件更新了问题。请复习,我复习了。使用完整的root build.gradle文件更新了问题。请检查。使用
-i
-d
标志运行会得到什么?那里应该有一个线索。我看到的唯一与
id
相关的消息是“设置文件中没有定义本地存储库。使用默认路径:/home/elad/.m2/repository”我想您缺少了
应用插件:
,请参阅我的更新答案运行
-I
-d
标志会得到什么?那里应该有个线索。我看到的唯一与
id
相关的消息是“设置文件中没有定义本地存储库。使用默认路径:/home/elad/.m2/repository”我想您缺少
应用插件:
,请参阅我的更新答案