〜/ .gradle / gradle.properties文件没有被读取 [英] ~/.gradle/gradle.properties file not being read

查看:684
本文介绍了〜/ .gradle / gradle.properties文件没有被读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个类似的问题: Gradle属性不是阅读〜/ .gradle / gradle.properties ,但它不能解决我的问题。



在我看来,gradle不读我的文件。

我在中有一个gradle.properties文件〜 /.gradle ,它具有在上传到maven central之前签署工件所需的属性。它看起来像这样:

  signing.keyId = 12345678 
signing.password = myPassword
signing.secretKeyRingFile = / home / me / .gnupg / secring.gpg

sonatypeUsername = me
sonatypePassword = myOtherPassword

当我尝试构建我的项目时,它抱怨没有sonatypeUsername属性,因此:

 >无法在根项目'yourProject'上找到属性'sonatypeUsername'。 

以下是我的项目build.gradle的相关部分:

  uploadArchives {
repositories {
mavenDeployer {

//很多无趣的东西在这里

repository(url:https://oss.sonatype.org/service/local/staging/deploy/maven2/){
authentication(userName:project.property(sonatypeUsername),password: project.property(sonatypePassword))
}
}
}
}

当我尝试通过调试来构建项目时,以下是我在属性中看到的内容:

  $ ./gradlew --stacktrace --debug build 

[INFO] [ogBuildLogger]开始构建
[DEBUG] [ogBuildLogger] Gradle用户home:/ home / me
[DEBUG] [ogBuildLogger]当前目录:/ home / me / dev / yourProject
[DEBUG] [ogBuildLogger]设置文件:null
[DEBUG] [ogBuildLogger] Build file:null
[DEBUG] [o.g.i.b.BuildSourceBuilder]开始构建构建源。
[DEBUG] [o.g.i.b.BuildSourceBuilder] Gradle源目录不存在。我们离开。
[DEBUG] [ogiDefaultGradlePropertiesLoader]找到env项目属性:[]
[DEBUG] [ogiDefaultGradlePropertiesLoader]找到系统项目属性:[]
[DEBUG] [ogaiamDefaultLocalMavenRepositoryLocator]在设置文件中定义。使用默认路径:/home/me/.m2/repository
[DEBUG] [o.g.i.ScriptEvaluatingSettingsProcessor]计时:处理设置花费:0.286秒
[INFO] [o.g.BuildLogger]使用空设置脚本评估的设置。
[DEBUG] [o.g.i.ProjectPropertySettingBuildLoader]从以下项目寻找项目属性:/home/me/dev/yourProject/gradle.properties
[调试] [o.g.i.ProjectPropertySettingBuildLoader]项目属性文件不存在。我们继续!
[INFO] [o.g.BuildLogger]已加载项目。使用构建文件/home/me/dev/yourProject/build.gradle的根项目。


解决方案

问题是我做了一个假设,没错。如果您查看 Gradle文档的第14.2节,它会说:


您可以将Gradle.properties文件放入Gradle用户主目录(由GRADLE_USER_HOME环境变量定义,如果未将缺省值设置为USER_HOME / .gradle)或在您的项目目录中。


我的错误假设是USER_HOME只默认了标准的linux HOME环境变量。这是不正确的。



只要我导出USER_HOME = $ HOME 在我的 〜/ .bashrc 一切正常


There is a similar question here: Gradle properties not being read from ~/.gradle/gradle.properties but it does not solve my problem.

It seems to me that gradle is NOT reading my ~/.gradle/gradle.properties file.

I have a gradle.properties file in ~/.gradle, and it has properties needed to sign artifacts before uploading to maven central. It looks like this:

signing.keyId=12345678
signing.password=myPassword
signing.secretKeyRingFile=/home/me/.gnupg/secring.gpg

sonatypeUsername=me
sonatypePassword=myOtherPassword

When I try to build my project, it complains that there's no sonatypeUsername property, thus:

> Could not find property 'sonatypeUsername' on root project 'yourProject'.

Here's the relevant portion of my project's build.gradle:

uploadArchives {
    repositories {
        mavenDeployer {

            // lots of non-interesting things here

            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
                authentication(userName: project.property("sonatypeUsername"), password: project.property("sonatypePassword"))
            }
        }
    }
}

When I try to build the project with debugging, here's what I see regarding properties:

$ ./gradlew --stacktrace --debug build

[INFO] [o.g.BuildLogger] Starting Build
[DEBUG] [o.g.BuildLogger] Gradle user home: /home/me
[DEBUG] [o.g.BuildLogger] Current dir: /home/me/dev/yourProject
[DEBUG] [o.g.BuildLogger] Settings file: null
[DEBUG] [o.g.BuildLogger] Build file: null
[DEBUG] [o.g.i.b.BuildSourceBuilder] Starting to build the build sources.
[DEBUG] [o.g.i.b.BuildSourceBuilder] Gradle source dir does not exist. We leave.
[DEBUG] [o.g.i.DefaultGradlePropertiesLoader] Found env project properties: []
[DEBUG] [o.g.i.DefaultGradlePropertiesLoader] Found system project properties: []
[DEBUG] [o.g.a.i.a.m.DefaultLocalMavenRepositoryLocator] No local repository in Settings file defined. Using default path: /home/me/.m2/repository
[DEBUG] [o.g.i.ScriptEvaluatingSettingsProcessor] Timing: Processing settings took: 0.286 secs
[INFO] [o.g.BuildLogger] Settings evaluated using empty settings script.
[DEBUG] [o.g.i.ProjectPropertySettingBuildLoader] Looking for project properties from: /home/me/dev/yourProject/gradle.properties
[DEBUG] [o.g.i.ProjectPropertySettingBuildLoader] project property file does not exists. We continue!
[INFO] [o.g.BuildLogger] Projects loaded. Root project using build file '/home/me/dev/yourProject/build.gradle'.

解决方案

The problem was that I made an assumption that wasn't true. If you look at section 14.2 of the gradle documentation, it says:

You can place a gradle.properties file in the Gradle user home directory (defined by the "GRADLE_USER_HOME" environment variable, which if not set defaults to USER_HOME/.gradle) or in your project directory.

My incorrect assumption was that USER_HOME just defaulted to the standard linux HOME environment variable. This is not true.

As soon as I export USER_HOME=$HOME in my ~/.bashrc everything works

这篇关于〜/ .gradle / gradle.properties文件没有被读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆