美文网首页
2019-10-29 初识gradle

2019-10-29 初识gradle

作者: 江江江123 | 来源:发表于2019-11-04 09:26 被阅读0次

    settings.gradle

    include '当前工程中的模块'
    includeBuild '其它工程'

    build.gradle

    //导入其它gradle 
    apply from: file("url")
    //定义静态常量 
    def x = ''
    //当前工程
    subprojects{
      group = '组名'
      version = '版本名'
      repositories {
        url '仓库地址'
        content {
          includeGroupByRegex: '包含内容的文件路径名 可用*添加多个' 
        }
      }
    
    }
    //具体配置:从当前工程下匹配模块
    configure(subprojects.findAll { it.name.matches('*.x')}){
         dependencies {
            implementation "具体依赖的包:版本号"
        }
    }
    //指定模块
    project(':模块名'){
        dependencies {
            implementation "具体依赖的包:版本号"
        }
    }
    //同时配置多个指定模块
    configure([project(':模块名'),project(':模块名')]){
      dependencies {
            implementation "具体依赖的包:版本号"
        }
    }
    
    

    project.gradle

    与gradle中的project.class一一对用

    //导入java类
    import java.time.Instant
    //默认任务
    defaultTasks 'clean', 'build'
    //当前工程配置
    subprojects {
        if (!childProjects.isEmpty()) return    // ignore parent project
        //应用插件
        apply plugin: 'java'
        apply plugin: 'maven'
        //源码兼容性
        sourceCompatibility = JavaVersion.VERSION_11
       //编译后目标文件兼容性
        targetCompatibility = JavaVersion.VERSION_11
        //任务类型批量设置
        tasks.withType(JavaCompile).configureEach {
            options.encoding = 'UTF-8'
            options.deprecation = true
            options.compilerArgs += ['-Xlint:all', '-proc:none']
        }
        //仓库配置
        repositories {
            mavenCentral()
            mavenLocal()
        }
        //打包路径
        buildDir = "${rootDir}/build/${rootDir.relativePath(projectDir)}"
       //测试任务配置
        tasks.named('test') {
            useJUnitPlatform()
            failFast = true
            testLogging.showStandardStreams = true
            testLogging.exceptionFormat 'full'
        }
      //jar文件设置
        tasks.named('jar') {
            // put parent name in final jar name, to resolve collision of child projects with same name under different parents
            if (parent.depth > 0) {
                archiveBaseName = "${parent.name}-${archiveBaseName.get()}"
            }
        }
    
        afterEvaluate {
            // update group on afterEvaluate since the project.gradle usually included in the first line of project build.gradle, which project.group is not assigned yet
            if (parent.depth > 0) {
                group = "${group}.${parent.name}"    // append parent into group, let child projects with same name under different parent have different artifactId
            }
    
            tasks.withType(Jar).configureEach {
                manifest {
                    attributes 'Implementation-Title': project.name,
                            'Implementation-Version': project.version,
                            'Created-By': "${System.getProperty('java.version')} (${System.getProperty('java.vendor')})",
                            'Built-With': "gradle ${project.gradle.gradleVersion}",
                            'Build-Time': Instant.now().toString()
                }
            }
        }
    }
    //导入验证文件
    apply from: file("${rootDir}/gradle/check.gradle")
    //所有工程配置
    allprojects {
        apply plugin: 'idea'
        idea.module.inheritOutputDirs = true
    }
    //gradle版本配置
    tasks.named('wrapper') {
        gradleVersion = '5.5'
    }
    
    

    相关文章

      网友评论

          本文标题:2019-10-29 初识gradle

          本文链接:https://www.haomeiwen.com/subject/avdwvctx.html