博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Gradle多项目配置的一个demo
阅读量:5834 次
发布时间:2019-06-18

本文共 7834 字,大约阅读时间需要 26 分钟。

 

ParentProject

├─build.gradle
├─settings.gradle
├─libs
├─subProject1
├────────────build.gradle
├────────────src/java
├────────────conf
├─subProject2
├────────────build.gradle
├────────────src/java
├────────────conf
├─subProject3
├────────────build.gradle
├────────────src/java
├────────────conf

ParentProject

目录下的build.gradle

//所有项目公用资源:IDE和库allprojects {    repositories {        mavenLocal()    }}//所有子项目公用:源码和单元测试代码定义subprojects {println "======================================"println "${rootProject.projectDir}/libs"println "======================================"    apply plugin: 'java'    sourceSets {        main {            java {                srcDir 'src/java'            }        }        test {            java {                srcDir 'src/test'            }        }     }         dependencies {        compile fileTree(dir: "${rootProject.projectDir}/liblicense",include: '**/*.jar')    } }

目录下的settings.gradle

include 'subProject1'include 'subProject2'include 'subProject3'//或include 'subProject1','subProject2','subProject3'

subProject1下的build.gradle

project(':subProject1') {    dependencies {    }}

subProject2下的build.gradle

project(':subProject2') {    dependencies {        compile project(':subProject1')    }}

subProject3下的build.gradle

project(':subProject3') {    dependencies {        compile project(':subProject1')    }}

 

graadle中的一个copy操作:

目录结构:

│  build.gradle│  gradlew│  gradlew.bat│  list.txt│  settings.gradle│  ├─.gradle│  └─2.8│      └─taskArtifacts│              cache.properties│              cache.properties.lock│              fileHashes.bin│              fileSnapshots.bin│              outputFileStates.bin│              taskArtifacts.bin│              ├─build│  ├─libs│  │      gradle.jar│  │      │  └─tmp│      └─jar│              MANIFEST.MF│              └─graldeCopyConfig    ├─build    │  ├─classes    │  │  ├─main    │  │  │      EqualDemo.class    │  │  │          │  │  └─test    │  │      │  EqualDemoTest.class    │  │      │      │  │      └─config    │  │              test.xml    │  │                  │  ├─dependency-cache    │  ├─libs    │  │      graldeCopyConfig.jar    │  │          │  ├─reports    │  │  └─tests    │  │      │  index.html    │  │      │      │  │      ├─classes    │  │      │      EqualDemoTest.html    │  │      │          │  │      ├─css    │  │      │      base-style.css    │  │      │      style.css    │  │      │          │  │      ├─js    │  │      │      report.js    │  │      │          │  │      └─packages    │  │              default-package.html    │  │                  │  ├─test-results    │  │  │  TEST-EqualDemoTest.xml    │  │  │      │  │  └─binary    │  │      └─test    │  │              output.bin    │  │              output.bin.idx    │  │              results.bin    │  │                  │  └─tmp    │      ├─compileJava    │      │  └─emptySourcePathRef    │      ├─compileTestJava    │      │  └─emptySourcePathRef    │      └─jar    │              MANIFEST.MF    │                  └─src        ├─main        │  ├─java        │  │      EqualDemo.java        │  │              │  └─resources        └─test            ├─java            │  │  EqualDemoTest.java            │  │              │  └─config            │          test.xml            │                      └─sources

build.gradle

/* * This build file was auto generated by running the Gradle 'init' task * by 'MyWorld' at '16-2-22 下午11:33' with Gradle 2.8 * * This generated file contains a commented-out sample Java project to get you started. * For more details take a look at the Java Quickstart chapter in the Gradle * user guide available at https://docs.gradle.org/2.8/userguide/tutorial_java_projects.html */subprojects {// Apply the java plugin to add support for Java    apply plugin: 'java'    sourceCompatibility = 1.6    targetCompatibility = 1.6    tasks.withType(JavaCompile) {        options.encoding = "UTF-8"    }    sourceSets {        main {            java {                srcDirs = ['src/main/java']            }        }        test {            java {                srcDirs = ['src/test/java']            }        }    }// In this section you declare where to find the dependencies of your project    repositories {        // Use 'jcenter' for resolving your dependencies.        // You can declare any Maven/Ivy/file repository here.        jcenter()    }    dependencies {        // The production code uses the SLF4J logging API at compile time        compile 'org.slf4j:slf4j-api:1.7.12'        // Declare the dependency for your favourite test framework you want to use in your tests.        // TestNG is also supported by the Gradle Test task. Just change the        // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add        // 'test.useTestNG()' to your build script.        testCompile 'junit:junit:4.12'    }    task copyConfig(type: Copy) {        from 'src/test/java'        into 'build/classes/test'        include '**/*.xml'        println fileTree('src/test/java').files        println fileTree('build/classes/test').files    }    test.dependsOn copyConfig}project(':graldeCopyConfig') {    // In this section you declare the dependencies for your production and test code    dependencies {    }}

settings.gradle

/* * This settings file was auto generated by the Gradle buildInit task * by 'MyWorld' at '16-2-22 下午11:33' with Gradle 2.8 * * The settings file is used to specify which projects to include in your build. * In a single project build this file can be empty or even removed. * * Detailed information about configuring a multi-project build in Gradle can be found * in the user guide at https://docs.gradle.org/2.8/userguide/multi_project_builds.html */include 'graldeCopyConfig'

gradle build的执行结果

[G:\java\gradle\graldeCopyConfig\src\test\java\EqualDemoTest.java, G:\java\gradle\graldeCopyConfig\src\test\java\config\test.xml][G:\java\gradle\graldeCopyConfig\build\classes\test\EqualDemoTest.class, G:\java\gradle\graldeCopyConfig\build\classes\test\config\test.xml]:graldeCopyConfig:compileJava UP-TO-DATE:graldeCopyConfig:processResources UP-TO-DATE:graldeCopyConfig:classes UP-TO-DATE:graldeCopyConfig:jar UP-TO-DATE:graldeCopyConfig:assemble UP-TO-DATE:graldeCopyConfig:copyConfig UP-TO-DATE:graldeCopyConfig:compileTestJava UP-TO-DATE:graldeCopyConfig:processTestResources UP-TO-DATE:graldeCopyConfig:testClasses UP-TO-DATE:graldeCopyConfig:test UP-TO-DATE:graldeCopyConfig:check UP-TO-DATE:graldeCopyConfig:build UP-TO-DATEBUILD SUCCESSFULTotal time: 5.196 secs

 

 

8.3. Dependency configurations

In Gradle dependencies are grouped into configurations. A configuration is simply a named set of dependencies. We will refer to them as dependency configurations. You can use them to declare the external dependencies of your project. As we will see later, they are also used to declare the publications of your project.

The Java plugin defines a number of standard configurations. These configurations represent the classpaths that the Java plugin uses. Some are listed below, and you can find more details in.

compile

The dependencies required to compile the production source of the project.

runtime

The dependencies required by the production classes at runtime. By default, also includes the compile time dependencies.

testCompile

The dependencies required to compile the test source of the project. By default, also includes the compiled production classes and the compile time dependencies.

testRuntime

The dependencies required to run the tests. By default, also includes the compile, runtime and test compile dependencies.

Various plugins add further standard configurations. You can also define your own custom configurations to use in your build. Please see  for the details of defining and customizing dependency configurations.

 

 

 

转载于:https://www.cnblogs.com/softidea/p/5133741.html

你可能感兴趣的文章
测试与调试
查看>>
9.18考试 第一题count题解
查看>>
mac zsh选择到行首的快捷键
查看>>
js的apply方法使用详解,绝对NB
查看>>
linux使用crontab实现PHP执行定时任务(转)
查看>>
LINQ To XML的一些方法
查看>>
C++成员初始化顺序
查看>>
[LeetCode] Copy List with Random Pointer
查看>>
openstack部署之nova
查看>>
QNX 线程 调度策略 优先级 时钟频率 同步
查看>>
day20-视图获取用户请求相关信息以及请求头
查看>>
Runtime
查看>>
JS组件系列——表格组件神器:bootstrap table
查看>>
LeetCode --- Convert Sorted Array to Binary Search Tree
查看>>
存储过程Oracle(一)
查看>>
log4j日志归档
查看>>
POJ 2007--Scrambled Polygon(计算凸包,点集顺序)
查看>>
HT全矢量化的图形组件设计
查看>>
LCA - 倍增法去求第几个节点
查看>>
Java笔记01——IO流
查看>>