简体   繁体   English

如何为所有新项目配置项目级别的 build.gradle?

[英]How to configure the project level build.gradle for all new projects?

My organization uses its own jrog artifactory and it's an internal website with username and password.我的组织使用自己的 jrog 神器,它是一个带有用户名和密码的内部网站。 Every time I create a new project in Android Studio, I need to change the project-level build.gradle file with my custom code and add the credentials in gradle.properties.每次在 Android Studio 中创建新项目时,我都需要使用我的自定义代码更改项目级别的 build.gradle 文件,并在 gradle.properties 中添加凭据。 Is there a way, where I will get my custom code loaded in build.gradle file every time I create a new project?有没有办法,每次我创建一个新项目时,我都会在 build.gradle 文件中加载我的自定义代码?

I am using Android Studio 4.1我正在使用 Android Studio 4.1

You can use Initialization Scripts (aka init scripts) to configure your corporate maven repository globally for all your projects:您可以使用初始化脚本(又名 init 脚本)为您的所有项目全局配置您的企业 Maven 存储库:

$user_home/.gradle/init.gradle : $user_home/.gradle/init.gradle

// configure private repo for all projects (root & sub projects)
allprojects {
    repositories {    
        mavenLocal()
        repositories {
            maven {
                name "Corporate repository"
                url "https://mycompany.org/maven-public"
                credentials {
                    username = ?????
                    password = ******
                }
            }
        }        
    }
}

Values for username & password can also be set globally , eg in your user-level gradle properties $user_home/.gradle/gradle.properties用户名和密码的值也可以全局设置,例如在您的用户级 gradle 属性$user_home/.gradle/gradle.properties

If you need to share this setup among your team, you could also create your own corporate Gradle wrapper distribution, which can pre-configure stuff like defaults plugins or common repositories;如果您需要在团队中共享此设置,您还可以创建自己的企业 Gradle 包装器发行版,它可以预先配置诸如默认插件或通用存储库之类的东西; this requires more work, but you can find example here : https://blog.mrhaki.com/2012/10/gradle-goodness-distribute-custom.html这需要更多的工作,但您可以在这里找到示例: https : //blog.mrhaki.com/2012/10/gradle-goodness-distribute-custom.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM