Reading a maven settings.xml when building with gradle?

前端 未结 6 2055
孤独总比滥情好
孤独总比滥情好 2021-01-30 18:21

I have a maven settings.xml located in:

 /home/u123/.m2/settings.xml

where I specify a remote maven repository:



        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 18:21

    See: https://github.com/ci-and-cd/maven-settings-decoder

    I use it in gradle build script to avoid expose nexus password in build.gradle or environment variable.

    buildscript {
      repositories {
        ...
        mavenCentral()
      }
      dependencies {
        ...
        classpath 'cn.home1.tools:maven-settings-decoder:1.0.5.OSS'
      }
    }
    ...
    ext.mavenSettings = new cn.home1.tools.maven.SettingsDecoder();
    ext.nexusSnapshotsUser = mavenSettings.getText("//server[id='${nexus}-snapshots']/username/text()")
    ext.nexusSnapshotsPass = mavenSettings.getText("//server[id='${nexus}-snapshots']/password/text()")
    println "${nexus}-snapshots username: " + mavenSettings.getText("//server[id='${nexus}-snapshots']/username/text()")
    println "${nexus}-snapshots password: " + mavenSettings.getText("//server[id='${nexus}-snapshots']/password/text()")
    ...
    

提交回复
热议问题