文档章节

gradle学习(9)-获取build相关信息

xxjbs001
 xxjbs001
发布于 2015/01/16 11:26
字数 1606
阅读 99
收藏 0

(以下所有内容都是根据官方文档学习。如果你对gradle有兴趣,希望你能直接学习官方文档,官方文档是最权威的。而且这样才能产生2份有意义的学习资料)


1.列举当前目录下的所有项目,包括子项目


qianhuis-Mac-mini:multproject qianhui$ gradle -q projects

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'multproject'
+--- Project ':api'
+--- Project ':services'
|    +--- Project ':services:shared'
|    \--- Project ':services:webservice'
\--- Project ':shared'

To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :api:tasks

在gradle后加projects,就可以列举出所有的项目,从上面的结果可以看出来。该目录的根目录为multproject。下面包括了api/services/shared三个子项目。其中services下面又包含了2个子项目shared/webservice。


2.列举任务


qianhuis-Mac-mini:multproject qianhui$ gradle -q tasks

------------------------------------------------------------
All tasks runnable from root project - The shared API for the application
------------------------------------------------------------

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles classes 'main'.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles classes 'test'.

Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]

Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.

Help tasks
----------
components - Displays the components produced by root project 'multproject'. [incubating]
dependencies - Displays all dependencies declared in root project 'multproject'.
dependencyInsight - Displays the insight into a specific dependency in root project 'multproject'.
help - Displays a help message.
projects - Displays the sub-projects of root project 'multproject'.
properties - Displays the properties of root project 'multproject'.
tasks - Displays the tasks runnable from root project 'multproject' (some of the displayed tasks may belong to subprojects).

IDE tasks
---------
cleanEclipse - Cleans all Eclipse files.
cleanEclipseWtp - Cleans Eclipse wtp configuration files.
eclipse - Generates all Eclipse files.
eclipseWtp - Generates Eclipse wtp configuration files.

Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.

To see all tasks and more detail, run with --all.

如果想再多的信息可以在后面加上--all,不过还是不要加的好,因为实在太多了。


3.搜索任务


qianhuis-Mac-mini:multproject qianhui$ gradle -q help --task test
Detailed task information for test

Paths
     :api:test
     :services:test
     :shared:test
     :services:shared:test
     :services:webservice:test

Type
     Test (org.gradle.api.tasks.testing.Test)

Options
     --debug-jvm     Enable debugging for the test process. The process is started suspended and listening on port 5005. [INCUBATING]

     --tests     Sets test class or method name to be included, '*' is supported.

Description
     Runs the unit tests.

上面是以test为关键字搜索匹配项。


4.列举依赖


qianhuis-Mac-mini:multproject qianhui$ gradle -q dependencies api:dependencies

------------------------------------------------------------
Root project - The shared API for the application
------------------------------------------------------------

No configurations

------------------------------------------------------------
Project :api
------------------------------------------------------------

archives - Configuration for archive artifacts.
No dependencies

compile - Compile classpath for source set 'main'.
\--- project :shared

default - Configuration for default artifacts.
\--- project :shared

runtime - Runtime classpath for source set 'main'.
\--- project :shared

testCompile - Compile classpath for source set 'test'.
+--- project :shared
\--- junit:junit:4.11
     \--- org.hamcrest:hamcrest-core:1.3

testRuntime - Runtime classpath for source set 'test'.
+--- project :shared
\--- junit:junit:4.11
     \--- org.hamcrest:hamcrest-core:1.3


例举出了api项目的依赖信息。


5.根据特定配置列举依赖


qianhuis-Mac-mini:multproject qianhui$ gradle -q dependencies api:dependencies --configuration testCompile

------------------------------------------------------------
Root project - The shared API for the application
------------------------------------------------------------

No configurations

------------------------------------------------------------
Project :api
------------------------------------------------------------

testCompile - Compile classpath for source set 'test'.
+--- project :shared
\--- junit:junit:4.11
     \--- org.hamcrest:hamcrest-core:1.3

6.获取插入依赖


获取项目中哪个任务依赖groovy的jar包


qianhuis-Mac-mini:multproject qianhui$ gradle -q api:dependencyInsight --dependency groovy --configuration testCompile
No dependencies matching given input were found in configuration ':api:testCompile'

7.列举项目属性


qianhuis-Mac-mini:multproject qianhui$ gradle -q api:properties

------------------------------------------------------------
Project :api
------------------------------------------------------------

allprojects: [project ':api']
ant: org.gradle.api.internal.project.DefaultAntBuilder@51cbc6c2
antBuilderFactory: org.gradle.api.internal.project.DefaultAntBuilderFactory@19661482
archivesBaseName: api
artifacts: org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler_Decorated@7ccc6fd4
asDynamicObject: org.gradle.api.internal.ExtensibleDynamicObject@51c2074e
assemble: task ':api:assemble'
baseClassLoaderScope: org.gradle.api.internal.initialization.DefaultClassLoaderScope@196dbbd1
binaries: [classes 'main', classes 'test']
build: task ':api:build'
buildDependents: task ':api:buildDependents'
buildDir: /Users/qianhui/Documents/Developer/gradle_project/0104/multproject/api/build
buildFile: /Users/qianhui/Documents/Developer/gradle_project/0104/multproject/api/build.gradle
buildNeeded: task ':api:buildNeeded'
buildScriptSource: org.gradle.groovy.scripts.UriScriptSource@7dd26a3e
buildTasks: [build]
buildscript: org.gradle.api.internal.initialization.DefaultScriptHandler@13d4cfb
check: task ':api:check'
childProjects: {}
class: class org.gradle.api.internal.project.DefaultProject_Decorated
classLoaderScope: org.gradle.api.internal.initialization.DefaultClassLoaderScope@5f88f35f
classes: task ':api:classes'
clean: task ':api:clean'
cleanEclipse: task ':api:cleanEclipse'
cleanEclipseClasspath: task ':api:cleanEclipseClasspath'
cleanEclipseJdt: task ':api:cleanEclipseJdt'
cleanEclipseProject: task ':api:cleanEclipseProject'
cleanEclipseWtp: task ':api:cleanEclipseWtp'
compileJava: task ':api:compileJava'
compileTestJava: task ':api:compileTestJava'
components: [org.gradle.api.internal.java.JavaLibrary@182212f9]
configurationActions: org.gradle.configuration.project.DefaultProjectConfigurationActionContainer@650ba5cf
configurations: [configuration ':api:archives', configuration ':api:compile', configuration ':api:default', 
configuration ':api:runtime', configuration ':api:testCompile', configuration ':api:testRuntime']
convention: org.gradle.api.internal.plugins.DefaultConvention@5fb2ecdc
defaultArtifacts: org.gradle.api.internal.plugins.DefaultArtifactPublicationSet_Decorated@5bdc9099
defaultTasks: []
dependencies: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@1446745
dependencyCacheDir: /Users/qianhui/Documents/Developer/gradle_project/0104/multproject/api/build/dependency-cache
dependencyCacheDirName: dependency-cache
depth: 1
description: null
displayName: root project 'multproject'
distsDir: /Users/qianhui/Documents/Developer/gradle_project/0104/multproject/api/build/distributions
distsDirName: distributions
docsDir: /Users/qianhui/Documents/Developer/gradle_project/0104/multproject/api/build/docs
docsDirName: docs
eclipse: org.gradle.plugins.ide.eclipse.model.EclipseModel_Decorated@6d995bec
eclipseClasspath: task ':api:eclipseClasspath'
eclipseJdt: task ':api:eclipseJdt'
eclipseProject: task ':api:eclipseProject'
eclipseWtp: task ':api:eclipseWtp'
ext: org.gradle.api.internal.plugins.DefaultExtraPropertiesExtension@6f621b2a
extensions: org.gradle.api.internal.plugins.DefaultConvention@5fb2ecdc
fileOperations: org.gradle.api.internal.file.DefaultFileOperations@11e59b87
fileResolver: org.gradle.api.internal.file.BaseDirFileResolver@7945c53e
gradle: build 'multproject'
group: multproject
inheritedScope: org.gradle.api.internal.ExtensibleDynamicObject$InheritedDynamicObject@5398a7a5
jar: task ':api:jar'
javadoc: task ':api:javadoc'
libsDir: /Users/qianhui/Documents/Developer/gradle_project/0104/multproject/api/build/libs
libsDirName: libs
logger: org.gradle.api.logging.Logging$LoggerImpl@4b266c83
logging: org.gradle.logging.internal.DefaultLoggingManager@479e3300
mayImplementMissingMethods: false
mayImplementMissingProperties: false
modelRegistry: org.gradle.model.internal.registry.DefaultModelRegistry@632669bb
module: org.gradle.api.internal.artifacts.ProjectBackedModule@79bc5432
name: api
parent: root project 'multproject'
parentIdentifier: root project 'multproject'
path: :api
plugins: [org.gradle.language.base.plugins.LifecycleBasePlugin@73258ce6, org.gradle.api.plugins.BasePlugin@385ec662, 
org.gradle.api.plugins.ReportingBasePlugin@754348e8, org.gradle.language.base.plugins.LanguageBasePlugin@35677c16, 
org.gradle.api.plugins.LegacyJavaComponentPlugin@2c8c4d3f, org.gradle.api.plugins.JavaBasePlugin@7ccd7637, 
org.gradle.api.plugins.JavaPlugin@5b39746e, org.gradle.plugins.ide.eclipse.EclipsePlugin@211c9201, 
org.gradle.plugins.ide.eclipse.EclipseWtpPlugin@6783c490, org.gradle.api.plugins.HelpTasksPlugin@690f268]
processOperations: org.gradle.api.internal.file.DefaultFileOperations@11e59b87
processResources: task ':api:processResources'
processTestResources: task ':api:processTestResources'
project: project ':api'
projectDir: /Users/qianhui/Documents/Developer/gradle_project/0104/multproject/api
projectEvaluationBroadcaster: ProjectEvaluationListener broadcast
projectEvaluator: org.gradle.configuration.project.LifecycleProjectEvaluator@6ee7a6d7
projectRegistry: org.gradle.api.internal.project.DefaultProjectRegistry@2a7aa623
properties: {...}
rebuildTasks: [clean, build]
reporting: org.gradle.api.reporting.ReportingExtension_Decorated@5a31599e
reportsDir: /Users/qianhui/Documents/Developer/gradle_project/0104/multproject/api/build/reports
repositories: [org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository_Decorated@5df2c254]
resources: org.gradle.api.internal.resources.DefaultResourceHandler@6cb448fb
rootDir: /Users/qianhui/Documents/Developer/gradle_project/0104/multproject
rootProject: root project 'multproject'
runtimeClasspath: file collection
scriptHandlerFactory: org.gradle.api.internal.initialization.DefaultScriptHandlerFactory@30238e7e
scriptPluginFactory: org.gradle.configuration.DefaultScriptPluginFactory@6e600ae2
serviceRegistryFactory: org.gradle.internal.service.scopes.ProjectScopeServices$5@636ab40a
services: ProjectScopeServices
sourceCompatibility: 1.7
sourceSets: [source set 'main', source set 'test']
sources: [source set 'main', source set 'test']
standardOutputCapture: org.gradle.logging.internal.DefaultLoggingManager@479e3300
state: project state 'EXECUTED'
status: integration
subprojects: []
targetCompatibility: 1.7
tasks: [task ':api:assemble', task ':api:build', task ':api:buildDependents', task ':api:buildNeeded', 
task ':api:check', task ':api:classes', task ':api:clean', task ':api:cleanEclipse', task ':api:cleanEclipseClasspath', 
task ':api:cleanEclipseJdt', task ':api:cleanEclipseProject', task ':api:cleanEclipseWtp', task ':api:compileJava', 
task ':api:compileTestJava', task ':api:eclipse', task ':api:eclipseClasspath', task ':api:eclipseJdt', 
task ':api:eclipseProject', task ':api:eclipseWtp', task ':api:jar', task ':api:javadoc', task ':api:processResources', 
task ':api:processTestResources', task ':api:properties', task ':api:test', task ':api:testClasses']
test: task ':api:test'
testClasses: task ':api:testClasses'
testReportDir: /Users/qianhui/Documents/Developer/gradle_project/0104/multproject/api/build/reports/tests
testReportDirName: tests
testResultsDir: /Users/qianhui/Documents/Developer/gradle_project/0104/multproject/api/build/test-results
testResultsDirName: test-results
version: unspecified

8.获取构建过程中的时间信息--profile


ianhuis-Mac-mini:multproject qianhui$ gradle build --profile
:shared:compileJava UP-TO-DATE
:shared:processResources UP-TO-DATE
:shared:classes UP-TO-DATE
:shared:jar UP-TO-DATE
:api:compileJava UP-TO-DATE
:api:processResources UP-TO-DATE
:api:classes UP-TO-DATE
:api:jar UP-TO-DATE
:api:assemble UP-TO-DATE
:api:compileTestJava UP-TO-DATE
:api:processTestResources UP-TO-DATE
:api:testClasses UP-TO-DATE
:api:test UP-TO-DATE
:api:check UP-TO-DATE
:api:build UP-TO-DATE
:services:compileJava UP-TO-DATE
:services:processResources UP-TO-DATE
:services:classes UP-TO-DATE
:services:jar UP-TO-DATE
:services:assemble UP-TO-DATE
:services:compileTestJava UP-TO-DATE
:services:processTestResources UP-TO-DATE
:services:testClasses UP-TO-DATE
:services:test UP-TO-DATE
:services:check UP-TO-DATE
:services:build UP-TO-DATE
:shared:assemble UP-TO-DATE
:shared:compileTestJava UP-TO-DATE
:shared:processTestResources UP-TO-DATE
:shared:testClasses UP-TO-DATE
:shared:test UP-TO-DATE
:shared:check UP-TO-DATE
:shared:build UP-TO-DATE
:services:shared:compileJava UP-TO-DATE
:services:shared:processResources UP-TO-DATE
:services:shared:classes UP-TO-DATE
:services:shared:jar UP-TO-DATE
:services:shared:assemble UP-TO-DATE
:services:shared:compileTestJava UP-TO-DATE
:services:shared:processTestResources UP-TO-DATE
:services:shared:testClasses UP-TO-DATE
:services:shared:test UP-TO-DATE
:services:shared:check UP-TO-DATE
:services:shared:build UP-TO-DATE
:services:webservice:compileJava UP-TO-DATE
:services:webservice:processResources UP-TO-DATE
:services:webservice:classes UP-TO-DATE
:services:webservice:jar UP-TO-DATE
:services:webservice:assemble UP-TO-DATE
:services:webservice:compileTestJava UP-TO-DATE
:services:webservice:processTestResources UP-TO-DATE
:services:webservice:testClasses UP-TO-DATE
:services:webservice:test UP-TO-DATE
:services:webservice:check UP-TO-DATE
:services:webservice:build UP-TO-DATE

BUILD SUCCESSFUL

Total time: 5.677 secs

在项目的build/reports/profile下会生成一个html文件,打开

可以看到一个报告。





9.dry run


就是模拟执行过程,但是并没有执行


qianhuis-Mac-mini:multproject qianhui$ gradle -m clean
:api:clean SKIPPED
:services:clean SKIPPED
:shared:clean SKIPPED
:services:shared:clean SKIPPED
:services:webservice:clean SKIPPED

BUILD SUCCESSFUL

会发现项目目录中里的build目录并没有被删除。而且上面的输出信息也可以看出SKIPPED。



本文转载自:http://blog.csdn.net/itfootball/article/details/42558993

xxjbs001
粉丝 55
博文 753
码字总数 217215
作品 0
浦东
QA/测试工程师
私信 提问
Learn Gradle - CH 3 Java 快速入门

上一章(链接)我们主要对Gradle的脚本进行了简要的介绍,本章我们将继续学习Gradle的另外一个特性——插件(plugins)。 1、插件介绍 插件是对Gradle功能的扩展,Gradle有着丰富的插件,你可...

Hassan
2015/07/26
91
0
全面理解Gradle - 执行时序

什么是Gradle? 一个像 Ant 一样的非常灵活的通用构建工具 一种可切换的, 像 maven 一样的基于合约构建的框架 支持强大的多工程构建 支持强大的依赖管理(基于 ApacheIvy ) 支持已有的 maven ...

SuShine
2018/08/31
103
0
Gradle入门系列(5):创建多项目构建

转载: 本文由 伯乐在线 - JustinWu 翻译,黄利民 校稿。未经许可,禁止转载! 英文出处:petrikainulainen。欢迎加入翻译组。 尽管我们可以仅使用单个组件来创建可工作的应用程序,但有时候...

低至一折起
2017/12/05
0
0
使用Sonar分析Ant/Maven/Gradle项目

Java构建工具 目前Java平台三大构建工具是:Apache Ant、Apache Maven、Gradle,当然还有其他几个高效、快速的编译工具,如:Google Bazel、Facebook Buck。 关于Apache Ant、Apache Maven、...

donhui
2016/03/10
829
0
Gradle入门系列(3):依赖管理

转载: 本文由 伯乐在线 - JustinWu 翻译。未经许可,禁止转载! 英文出处:Petri Kainulainen。欢迎加入翻译组。 在现实生活中,要创造一个没有任何外部依赖的应用程序并非不可能,但也是极...

低至一折起
2017/12/05
0
0

没有更多内容

加载失败,请刷新页面

加载更多

3_数组

3_数组

行者终成事
今天
7
0
经典系统设计面试题解析:如何设计TinyURL(二)

原文链接:https://www.educative.io/courses/grokking-the-system-design-interview/m2ygV4E81AR 编者注:本文以一道经典的系统设计面试题:《如何设计TinyURL》的参考答案和解析为例,帮助...

APEMESH
今天
7
0
使用logstash同步MySQL数据到ES

概述   在生成业务常有将MySQL数据同步到ES的需求,如果需要很高的定制化,往往需要开发同步程序用于处理数据。但没有特殊业务需求,官方提供的logstash就很有优势了。   在使用logstas...

zxiaofan666
今天
10
0
X-MSG-IM-分布式信令跟踪能力

经过一周多的鏖战, X-MSG-IM的分布式信令跟踪能力已基本具备, 特点是: 实时. 只有要RX/TX就会实时产生信令跟踪事件, 先入kafka, 再入influxdb待查. 同时提供实时sub/pub接口. 完备. 可以完整...

dev5
今天
7
0
OpenJDK之CyclicBarrier

OpenJDK8,本人看的是openJDK。以前就看过,只是经常忘记,所以记录下 图1 CyclicBarrier是Doug Lea在JDK1.5中引入的,作用就不详细描述了,主要有如下俩个方法使用: await()方法,如果当前线...

克虏伯
今天
8
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部