摇篮 - 有条件地添加配置

问题描述:

我有一个配置的gradle这个项目下面摇篮 - 有条件地添加配置

apply plugin: 'java' 
apply plugin: 'maven' 

repositories { 
    mavenCentral() 

    maven { 
     credentials { 
      username "$System.env.REPOSITORY_USER" 
      password "$System.env.REPOSITORY_PWD" 
     } 
     url "$System.env.REPOSITORY_HOME" + /nexus/content/groups/public/" 
    } 
} 

理想的情况下只在构建服务器应该知道存储库的用户名和具有发布权的密码,其他人应该有只读权限(凭据块不应该被应用)。有没有办法根据REPOSITORY_USERREPOSITORY_PWD是否填充,有条件地添加credentials块?

如果您有任何建议,我愿意提供更好的解决方案!

尝试使用这样的:

repositories { 
    mavenCentral() 
} 

if (System.env.REPOSITORY_USER != null && System.env.REPOSITORY_PWD != null) { 
    repositories { 
     maven { 
      // Setup here what you need 
      credentials { 
      } 
     } 
    } 
}