Maven发布存储库凭据取决于自定义任务

时间:2019-08-14 13:58:16

标签: gradle build.gradle maven-publish

我有一个自定义任务,可从服务器获取凭据:

task getToken {
    ext.token = // curl whatever
}

我想在出版物存储库的凭据块中使用此任务的输出,如下所示:

publishing {
    publications {
        myPublication(MavenPublication) {
            from components.java
        }
    }

    repositories {
        maven {
            url = "https://somewhere.com/repo"

            credentials {
                username System.properties['user.name']
                password getToken.token
            }
        }
    }
}

但是,我不知道何时解决那里的凭证,显然getToken任务需要事先完成。

我该如何实现?

1 个答案:

答案 0 :(得分:0)

这是可以通过以下插件实现的:https://plugins.gradle.org/plugin/pl.unity.lazy-credentials

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
        classpath "gradle.plugin.pl.unity.gradle:lazy-credentials:1.2.1"
    }
}

apply plugin: "pl.unity.lazy-credentials"

publishing {
    publications {
        myPublication(MavenPublication) {
            from components.java
        }
    }

    repositories {
        maven {
            url "https://somewhere.com/repo"
            lazyCredentials {
                username System.properties['user.name']
                password {
                    // some code here to request the token
                }
            }
        }
    }
}
相关问题