上海 网站开发 兼职,外贸网站建设 佛山,平面广告创意作品,深圳网站建设注册概述命令学习比较枯燥#xff0c;全部是例子~gradle版本假设你的本地gradle已经安装配置完成。没有安装配置的#xff0c;可以参考 gradle安装C:\Users\yueling.DANGDANGgradle -v------------------------------------------------------------Gradle 4.5.1------------…概述命令学习比较枯燥全部是例子~gradle版本假设你的本地gradle已经安装配置完成。没有安装配置的可以参考 gradle安装C:\Users\yueling.DANGDANGgradle -v------------------------------------------------------------Gradle 4.5.1------------------------------------------------------------Build time: 2018-02-05 13:22:49 UTCRevision: 37007e1c012001ff09973e0bd095139239ecd3b3Groovy: 2.4.12Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017JVM: 1.8.0_73 (Oracle Corporation 25.73-b02)OS: Windows 7 6.1 amd64C:\Users\yueling.DANGDANG语法gradle [taskName...][--option-name...]gradlew是包装器自动下载包装里定义好的gradle 版本保证编译环境统一gradle 是用本地的gradle。所以./gradlew、gradle通用不神秘使用更方便一些,可以使用gradle互相替换。其中gradlew的内容可以在项目的目录下查看。任务如果需要处理多任务任务列表必须使用空格分割开如gradle test deploy选项选项可以放在任务列表前也可以放在任务列表后如下的写法作用是相同的gradle --consoleplain testgradle test --consoleplain记忆技巧长格式的选项 表示启用特性的都具有反向操作(关闭特性)关闭特性长选项格式在启用特性前缀no---build-cache--configure-on-demand--daemon--parallel--scan--no-build-cache--no-configure-on-demand--no-daemon--no-parallel--no-scan命令列表打开控制台command_Parametersintroduction-?, -h, –help展示帮助信息-a, –no-rebuild忽略构建”项目依赖”,[废弃]-b, –build-file使用用-b参数将会忽略setting文件,用指定的.gradle文件进行构建(默认情况下首先会寻找当前目录下的 build.gradle文件或依据settings.gradle中的配置寻找子项目中的build.gradle)–build-cache支持gradle缓存。Gradle将试图重用以前的版本的输出-c, –settings-file执行指定的*.gralde文件(默认settings.gradle)–configure-on-demand配置必要的项目。Gradle将试图减少大型多项目构建的配置时间–console指定控制台输出类型,可选值有’plain’、’auto’(默认)、’rich’、’verbose’。plain 是生成普通的文本该选项禁止所有颜色和富文本输出;auto当构建程序与控制台相关联时启动颜色和富文本输出或者不关联时生成普通文本;rich 启动颜色和富文本输出忽略构建程序是否关联了控制台,如果没有关联构建输出将输出 ANSI 控制字符来生产富文本输出;verbose会输出更多的详细信息(感觉很乱调试问题可能会用到)–continue构建时遇到错误忽略报错,继续构建,默认报错后终止构建-D, –system-prop-D属性会被传送给启动Gradle的jvm作为一个系统属性被jvm使用(例如:-Dmypropmyvalue)-d, –debug指定日志输出级别为debug,可打印一般堆栈信息–daemon使用Gradle守护进程执行构建,如果没有守护进程则启动一个守护进程–foreground以foreground形式启动守护进程-g, –gradle-user-home指定默认的指定Gradle 用户home目录.默认在”用户目录/.gradle”-I, –init-script运行指定初始化脚本,脚本会在build之前执行.查找init.gradle的路径顺序./,USER_HOME/.gradle/ ,USER_HOME/.gradle/init.d/,GRADLE_HOME/init.d/-i, –info指定日志级别为info–include-build在组合中包含指定的构建-m, –dry-run模拟任务执行过程并将过程打印出来,并非真正执行,目的是展示执行的过程–max-workers设定参与构建的cpu的核数–no-build-cache禁用构建缓存–no-configure-on-demand根据需要禁用配置–no-daemon禁用守护进程,不使用守护进程执行构建. 如果你已经配置了Gradle总会使用守护进程运行此选项有帮助–no-parallel禁止使用并行模式构建项目–offline采用离线模式构建项目,不使用网路资源(此时很有可能出现构建失败的情况慎用)-P, –project-prop设置Gradle的项目参数,会被直接加载到Gradle领域对象上(例如:-Pmypropmyvalue)-p, –project-dir为gradle指定起始目录。默认为当前目录–parallel采用并行模式构建。gradle采用配置的线程数进行构建–profile存储一份执行报告到/reports/profile,包括总时间和在配置和任务执行阶段的细节。并以时间大小倒序排列并且记录了任务的执行情况.Gradle会根据构建时间命名这些报告文件–project-cache-dir指定项目的缓存目录。默认在项目目录中。-q, –quiet静默方式只输出error信息–recompile-scripts强制构建脚本重新编译[废弃]–refresh-dependencies刷新依赖的状态–rerun-tasks忽略先前缓存的任务结果-S, –full-stacktrace打印全部详细信息所有异常的堆栈信息-s, –stacktrace打印所有异常的堆栈信息–scan创建一个构建扫描。如果构建扫描插件没有被应用那么gradle会发出警告(https://gradle.com/build-scans)–status统计信息展示正在运行和最近停止的gradle进程–stop如果守护进程正在运行停止gradle的守护进程-t, –continuous连续构建模式,采用此模式后会监听所有构建文件变化,文件发生变化后会自动重新构建-u, –no-search-upward不使用父目录中的settings.gradle文件,如果不添加此项,父目录的setting.gradle会覆盖子目录下的配置-v, –version打印gradle版本信息-w, –warn指定日志级别为warn–warning-mode指定要生成的警告模式。值是’all’, ‘summary’(默认) or ‘no’-x, –exclude-task任务排除,跳过执行指定任务命令的一些用法准备一个项目使用eclipse创建一个gradle的项目:gradleDemo该项目不写任何代码只配置build.gradle,只为了演示命令的基本用法及效果build.gradleapply plugin: java-library// In this section you declare where to find the dependencies of your projectrepositories {// Use jcenter for resolving your dependencies.// You can declare any Maven/Ivy/file repository here.jcenter()}dependencies {// This dependency is exported to consumers, that is to say found on their compile classpath.api org.apache.commons:commons-math3:3.6.1// This dependency is used internally, and not exposed to consumers on their own compile classpath.implementation com.google.guava:guava:23.0// Use JUnit test frameworktestImplementation junit:junit:4.12}//有依赖task base {doLast {println im base!}}task extend(dependsOn: base) {doLast {println Im extend!}}//使用task dolast println show me! dolastprintln (show me! dolast)println (show me! dolast);}//多字节名称使用间歇eEEtask extendExpExp() {doLast {println Im extendExpExp}}实验挑一些常用的命令用实例说明用法,首先切换到项目所在目录Microsoft Windows [版本 6.1.7601]版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:\Users\yueling.DANGDANGcd /d d:\eclipsWS\gradleWS\gradleDemod:\eclipsWS\gradleWS\gradleDemo直接执行命令d:\eclipsWS\gradleWS\gradleDemogradle:helpWelcome to Gradle 4.5.1.To run a build, run gradle ...To see a list of available tasks, run gradle tasksTo see a list of command-line options, run gradle --helpTo see more detail about a task, run gradle help --task Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 1s1 actionable task: 1 executed执行任务和任务的所有依赖d:\eclipsWS\gradleWS\gradleDemogradle extend:baseim base!:extendIm extend!Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 0s2 actionable tasks: 2 executed多模块项目中可以在root项目中指定项目名称来执行,此项目时单模块的不在此演示,格式为 gradle projectName:taskName多任务执行d:\eclipsWS\gradleWS\gradleDemogradle base dolast:baseim base!:dolastshow me! dolastshow me! dolastshow me! dolastDeprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 0s2 actionable tasks: 2 executed排除模块执行d:\eclipsWS\gradleWS\gradleDemogradle base dolast -x dolast:baseim base!Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 0s1 actionable task: 1 executed强制执行任务d:\eclipsWS\gradleWS\gradleDemogradle base --rerun-tasks:baseim base!Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 1s1 actionable task: 1 executed遇到错误继续执行d:\eclipsWS\gradleWS\gradleDemogradle base --continue:baseim base!Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 0s1 actionable task: 1 executed当然目前该项目没有错误^_^task控制 doFirst 和doLast在这里我们使用它来控制一些输出作为演示(实际项目中可以填入更复杂的actions)前面的例子中已经使用了还可以更灵活第控制,如在build.gradle中配置添加base.doLast {println addtion end......}base.doFirst {println addtion start......}那么输入就会改变在任务开始和结束打印的内容随之变化d:\eclipsWS\gradleWS\gradleDemogradle base:baseaddtion start......im base!addtion end......Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 1s1 actionable task: 1 executed静默构建多余的日志信息不见了~~~d:\eclipsWS\gradleWS\gradleDemogradle -q baseaddtion start......im base!addtion end......d:\eclipsWS\gradleWS\gradleDemo设置日志级别分别演示了设置成warn和info的情况d:\eclipsWS\gradleWS\gradleDemogradle -w baseaddtion start......im base!addtion end......Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsd:\eclipsWS\gradleWS\gradleDemogradle -i baseInitialized native services in: C:\Users\yueling.DANGDANG\.gradle\nativeThe client will now receive all logging from the daemon (pid: 59652). The daemon log file: C:\Users\yueling.DANGDANG\.gradle\daemon\4.5.1\daemon-59652.out.logStarting 33rd build in daemon [uptime: 3 hrs 53 mins 31.583 secs, performance: 100%, no major garbage collections]Using 4 worker leases.Starting BuildSettings evaluated using settings file D:\eclipsWS\gradleWS\gradleDemo\settings.gradle.Projects loaded. Root project using build file D:\eclipsWS\gradleWS\gradleDemo\build.gradle.Included projects: [root project gradleDemo]Evaluating root project gradleDemo using build file D:\eclipsWS\gradleWS\gradleDemo\build.gradle.All projects evaluated.Selected primary task base from project :Tasks to be executed: [task :base]:base (Thread[Daemon worker Thread 17,5,main]) started.:baseTask :base is not up-to-date because:Task has not declared any outputs.addtion start......im base!addtion end......:base (Thread[Daemon worker Thread 17,5,main]) completed. Took 0.0 secs.Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 1s1 actionable task: 1 executedVCS Checkout Cache (D:\eclipsWS\gradleWS\gradleDemo\.gradle\vcsWorkingDirs) has not been cleaned up in 0 days控制台输出类型可以指定的类型有’plain’、’auto’(默认)、’rich’、’verbose’d:\eclipsWS\gradleWS\gradleDemogradle base --console plain:baseaddtion start......im base!addtion end......Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 0s1 actionable task: 1 executedd:\eclipsWS\gradleWS\gradleDemogradle base --console rich[1A[1m 0% CONFIGURING [0s][m[35D[1B[1A[0K[1m Task :base[m[33m [39maddtion start......im base!addtion end......Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warnings[32;1mBUILD SUCCESSFUL[0;39m in 0s1 actionable task: 1 executedwindows下显示有点问题不支持颜色的控制~尊驾可以移步到linux下执行颜色等都显示出来了statusd:\eclipsWS\gradleWS\gradleDemogradle base --statusPID STATUS INFO59652 IDLE 4.5.1Only Daemons for the current Gradle version are displayed. See https://docs.gradle.org/4.5.1/userguide/gradle_daemon.html#sec:statusscan这个过程是需要交互的同意即可即输入yes然后按提供的地址打开url提供邮件地址按邮件里的提示查看报告d:\eclipsWS\gradleWS\gradleDemogradle base --scan:baseaddtion start......im base!addtion end......Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 2s1 actionable task: 1 executedPublishing a build scan to scans.gradle.com requires accepting the Terms of Service defined at https://scans.gradle.com/terms-of-service. Do you accept these terms? [yes, no]yesGradle Cloud Services license agreement accepted.Publishing build scan...https://gradle.com/s/pmnnhqgqmv4zw更换setting.gradle配置文件将一份配置文件复制到项目外(本例直接复制到d盘),修改其中的项目名称为gradleDemooooooooooooorootProject.name gradleDemoooooooooooood:\eclipsWS\gradleWS\gradleDemogradle base -c d:\settings.gradle -iInitialized native services in: C:\Users\yueling.DANGDANG\.gradle\nativeThe client will now receive all logging from the daemon (pid: 59652). The daemon log file: C:\Users\yueling.DANGDANG\.gradle\daemon\4.5.1\daemon-59652.out.logStarting 45th build in daemon [uptime: 4 hrs 20 mins 27.835 secs, performance: 100%, no major garbage collections]Using 4 worker leases.Starting BuildSettings evaluated using settings file D:\settings.gradle.Projects loaded. Root project using build file D:\build.gradle.Included projects: [root project gradleDemooooooooooooo]Evaluating root project gradleDemooooooooooooo using build file D:\build.gradle.All projects evaluated.Selected primary task base from project :Tasks to be executed: [task :base]:base (Thread[Task worker for :,5,main]) started.:baseTask :base is not up-to-date because:Task has not declared any outputs.addtion start......im base!addtion end......:base (Thread[Task worker for :,5,main]) completed. Took 0.001 secs.Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 1s1 actionable task: 1 executedVCS Checkout Cache (D:\.gradle\vcsWorkingDirs) has not been cleaned up in 0 days更换build.gradle配置文件复制一份配置文件到D盘并添加任务task baseadd {doLast {println build.gradle not in dir!}}d:\eclipsWS\gradleWS\gradleDemogradle baseadd -b d:\build.gradle:baseaddbuild.gradle not in dir!Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 0s1 actionable task: 1 executedgradle build装配所有输出并运行所有检查d:\eclipsWS\gradleWS\gradleDemogradle build:compileJava:processResources NO-SOURCE:classes:jar:assemble:compileTestJava:processTestResources NO-SOURCE:testClasses:test:check:buildDeprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 18s4 actionable tasks: 4 executedgradle run运行所有任务gradle check验证任务包括测试和初始化d:\eclipsWS\gradleWS\gradleDemogradle check:compileJava:processResources NO-SOURCE:classes:compileTestJava:processTestResources NO-SOURCE:testClasses:test:checkDeprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 2s3 actionable tasks: 3 executedgradle clean清理所有输出d:\eclipsWS\gradleWS\gradleDemogradle clean:cleanDeprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 0s1 actionable task: 1 executedgradle projects项目报告,包括子项目d:\eclipsWS\gradleWS\gradleDemogradle projects:projects------------------------------------------------------------Root project------------------------------------------------------------Root project gradleDemoNo sub-projectsTo see a list of the tasks of a project, run gradle :tasksFor example, try running gradle :tasksDeprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 0s1 actionable task: 1 executedgradle tasks所有的tasks列表d:\eclipsWS\gradleWS\gradleDemogradle tasks:tasks------------------------------------------------------------All tasks runnable from root project------------------------------------------------------------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 main classes.clean - Deletes the build directory.jar - Assembles a jar archive containing the main classes.testClasses - Assembles test classes.Build Setup tasks-----------------init - Initializes a new Gradle build.wrapper - Generates Gradle wrapper files.Documentation tasks-------------------javadoc - Generates Javadoc API documentation for the main source code.Help tasks----------buildEnvironment - Displays all buildscript dependencies declared in root project gradleDemo.components - Displays the components produced by root project gradleDemo. [incubating]dependencies - Displays all dependencies declared in root project gradleDemo.dependencyInsight - Displays the insight into a specific dependency in root project gradleDemo.dependentComponents - Displays the dependent components of components in root project gradleDemo. [incubating]help - Displays a help message.model - Displays the configuration model of root project gradleDemo. [incubating]projects - Displays the sub-projects of root project gradleDemo.properties - Displays the properties of root project gradleDemo.tasks - Displays the tasks runnable from root project gradleDemo.Verification tasks------------------check - Runs all checks.test - Runs the unit tests.Rules-----Pattern: clean: Cleans the output files of a task.Pattern: build: Assembles the artifacts of a configuration.Pattern: upload: Assembles and uploads the artifacts belonging to a configuration.To see all tasks and more detail, run gradle tasks --allTo see more detail about a task, run gradle help --task Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warningsBUILD SUCCESSFUL in 1s1 actionable task: 1 executedgradle tasks –allgradle -q help –task base展示指定任务的详细信息d:\eclipsWS\gradleWS\gradleDemogradle -q help --task baseDetailed task information for basePath:baseTypeTask (org.gradle.api.Task)Description-Group-gradle dependencies展示项目依赖d:\eclipsWS\gradleWS\gradleDemogradle dependencies:dependencies------------------------------------------------------------Root project------------------------------------------------------------api - API dependencies for source set main. (n)\--- org.apache.commons:commons-math3:3.6.1 (n)apiElements - API elements for main. (n)No dependenciesarchives - Configuration for archive artifacts.No dependenciescompile - Dependencies for source set main (deprecated, use implementation instead).No dependenciescompileClasspath - Compile classpath for source set main.--- org.apache.commons:commons-math3:3.6.1\--- com.google.guava:guava:23.0--- com.google.code.findbugs:jsr305:1.3.9--- com.google.errorprone:error_prone_annotations:2.0.18--- com.google.j2objc:j2objc-annotations:1.1\--- org.codehaus.mojo:animal-sniffer-annotations:1.14compileOnly - Compile only dependencies for source set main.No dependencies……gradle buildEnvironment展示构建环境依赖关系报告gradle dependencyInsight展示依赖关系报告gradle model展示模型关系报告d:\eclipsWS\gradleWS\gradleDemogradle model:model------------------------------------------------------------Root project------------------------------------------------------------ binaries| Type: org.gradle.platform.base.BinaryContainer| Creator: BinaryBasePlugin.Rules#binaries(BinaryContainer)| Rules:? JavaBasePlugin.Rules#attachBridgedBinaries(BinaryContainer, JavaBasePlugin.BridgedBinaries) main| Type: org.gradle.api.internal.jvm.DefaultClassDirectoryBinarySpec_Decorated| Value: Classes main| Creator: JavaBasePlugin.Rules#attachBridgedBinaries(BinaryContainer, JavaBasePlugin.BridgedBinaries) put()| Rules:? BinaryBasePlugin.Rules#defineBuildLifecycleTask(BinarySpecInternal, ITaskFactory)? BinaryBasePlugin.Rules#addSourceSetsOwnedByBinariesToTheirInputs(BinarySpecInternal) test| Type: org.gradle.api.internal.jvm.DefaultClassDirectoryBinarySpec_Decorated| Value: Classes test| Creator: JavaBasePlugin.Rules#attachBridgedBinaries(BinaryContainer, JavaBasePlugin.BridgedBinaries) put()| Rules:? BinaryBasePlugin.Rules#defineBuildLifecycleTask(BinarySpecInternal, ITaskFactory)? BinaryBasePlugin.Rules#addSourceSetsOwnedByBinariesToTheirInputs(BinarySpecInternal) components| Type: org.gradle.platform.base.ComponentSpecContainer| Creator: ComponentBasePlugin.PluginRules#components(ComponentSpecContainer)……还有一些没有演示的命令根据帮助文档都能尝试一下