├── .gitignore ├── LICENCE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pics ├── launch.png ├── upload.png ├── uploadAll.png └── uploadArchives.png ├── settings.gradle └── speedup ├── .gitignore ├── build.gradle └── src └── main ├── groovy └── org │ └── component │ └── gradle │ ├── ReplacePlugin.groovy │ ├── RootPlugin.groovy │ └── UploadPlugin.groovy └── resources └── META-INF └── gradle-plugins └── speedup.properties /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/ 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright Haoge(https://github.com/yjfnypeu) 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Speedup 2 | 3 | Speedup是一款针对于多组件构建加速的插件。特别是针对组件化开发,作用尤为明显。 4 | 5 | ### 什么人需要Speedup 6 | 7 | 随着项目不停迭代升级,项目越来越大,特别是最近两年开始流行了组件化之后。可能拆分的组件越来越多。 8 | 越来越细。导致项目下开启了一堆的module.每次运行的时候都会因此耗费大量的时间。 9 | 10 | Speedup即是专用于解决此类由于堆积了一堆module之后的编译卡顿问题 11 | 12 | ### 原理 13 | 14 | 1. 将library打包发布到指定的本地maven仓库中 15 | 2. 启动运行任务时,自动查找本地build.gradle中配置的compile project依赖。替换为本地maven仓库中的aar地址 16 | 17 | ### 配置 18 | 19 | 在项目根目录下添加依赖并添加应用插件 20 | 21 | latest = [![](https://jitpack.io/v/yjfnypeu/Speedup.svg)](https://jitpack.io/#yjfnypeu/Speedup) 22 | 23 | ```groovy 24 | buildscript { 25 | repositories { 26 | // 添加jitpack仓库地址 27 | maven { url "https://jitpack.io" } 28 | } 29 | dependencies { 30 | // 添加插件依赖 31 | classpath "com.github.yjfnypeu:Speedup:$latest" 32 | } 33 | } 34 | // 应用插件 35 | apply plugin: 'speedup' 36 | ``` 37 | 38 | 插件将配置属性放入local.properties文件中进行配置。更方便个人单独使用 39 | 40 | - local.properties 41 | 42 | ``` 43 | speedup.enable=true 44 | localRepo=localUrl 45 | excludeModules=modulepath1,modulepath2 46 | ``` 47 | 48 | - speedup.enable 49 | 50 | 此属性用于指定是否激活加速插件。默认为false。主要用于针对比如使用Jenkins打包发布时,不使用加速插件。 51 | 52 | - localRepo 53 | 54 | 此属性提供用于定制所使用的本地仓库地址。若不配置则默认使用项目根目录下的_repo目录作为本地仓库地址。 **(请注意将此目录加入版本控制忽略表中。避免提交)** 55 | 56 | - excludeModules 57 | 58 | 此属性的值为module的path值。即在settings.gradle中使用include所指定的路径地址: 59 | 如 excludeModules=:app,:lib 60 | 61 | 此属性用于指定不需要被加速的组件模块, 比如说组件化中的各自的业务线组件。 62 | 这类组件因为是各自开发业务线的主module。需要随时变更改动。所以将其排除 63 | 64 | application module被默认排除的。不需要再进行单独配置 65 | 66 | ### 用法 67 | 68 | 主要用法是将module进行打包发布到本地maven库中去,发布方式分为两种: 69 | 70 | - 使用全量打包发布: 71 | 72 | 使用提供的uploadAll任务进行全量打包发布。这种发布方式一般在切换分支后进行使用。 73 | 74 | ``` 75 | ./gradlew uploadAll 76 | ``` 77 | 78 | - 对于部分module打包发布 79 | 80 | 不同的library含有各自单独的upload方法,如模块名为:loginLib: 81 | 82 | ``` 83 | ./gradlew uploadloginLib 84 | ``` 85 | 86 | 或者可使用AS提供的gradle任务视图窗口直接进行使用: 87 | 88 | ![upload](./pics/upload.png) 89 | 90 | 然后直接通过![launch](./pics/launch.png)进行启动即可。和平时开发时一样 91 | 92 | #### 问答 93 | 94 | - 为什么不直接使用uploadArchives任务进行直接打包发布? 95 | 96 | 这是为了能更方便更快速的进行打包编译。 97 | 98 | 因为如果直接使用AS的gradle任务窗口中的uploadArchives任务时:会触发使用root project的uploadArchives命令。 99 | 导致其实一些不需要在此时被编译的模块也都会进行编译打包,严重影响了发布速度。 100 | 101 | 而使用命令行的方式执行单个的module的uploadArchives任务可以避免以上情况,但是略显复杂,容易使用不顺 102 | 103 | 以下为使用demo进行测试时,完全clean后分别使用uploadAll以及uploadArchives时的运行时间对比: 104 | 105 | ![uploadAll](./pics/uploadAll.png) 106 | 107 | ![uploadArchives](./pics/uploadArchives.png) 108 | 109 | - 我直接搭个远程仓库就可以打包发布了。为什么要来用这种打包发布到本地的策略用法? 110 | 111 | 远程仓库和本地仓库各有特点。本地仓库的最主要特点是version不唯一,即可不用每次都去修改版本号再发布,完全可以同一个版本覆盖发布。 112 | 113 | 个人给的建议是:对于一些基本已经比较稳定了的library,可选择发布到远程仓库中去。而对于组件化这种形式的。大部分的library其实是一直在变一直在修改的。可选择发布到本地仓库中。避免过于频繁的修改版本号打包发布。 114 | 115 | #### 示例 116 | 117 | ***可参考[一个简单的组件化demo](https://github.com/yjfnypeu/AndroidComponent)*** 118 | 119 | ### 联系作者 120 | email: 470368500@qq.com 121 | 122 | 安卓交流会所 123 | 124 | 或者手动加入QQ群: 108895031 125 | 126 | ## License 127 | [apache 2.0](./LICENCE) -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | maven { url "https://jitpack.io" } 6 | jcenter() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:2.3.3' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | maven { url "https://jitpack.io" } 19 | jcenter() 20 | } 21 | } 22 | 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } 26 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JumeiRdGroup/Speedup/828a4a4d2fcedafe4830da71c106af7b214d629c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Oct 21 08:54:24 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /pics/launch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JumeiRdGroup/Speedup/828a4a4d2fcedafe4830da71c106af7b214d629c/pics/launch.png -------------------------------------------------------------------------------- /pics/upload.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JumeiRdGroup/Speedup/828a4a4d2fcedafe4830da71c106af7b214d629c/pics/upload.png -------------------------------------------------------------------------------- /pics/uploadAll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JumeiRdGroup/Speedup/828a4a4d2fcedafe4830da71c106af7b214d629c/pics/uploadAll.png -------------------------------------------------------------------------------- /pics/uploadArchives.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JumeiRdGroup/Speedup/828a4a4d2fcedafe4830da71c106af7b214d629c/pics/uploadArchives.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':speedup' 2 | -------------------------------------------------------------------------------- /speedup/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /speedup/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | apply plugin: 'maven' 3 | 4 | repositories { 5 | jcenter() 6 | mavenCentral() 7 | mavenLocal() 8 | } 9 | 10 | dependencies { 11 | compile gradleApi() 12 | compile localGroovy() 13 | } 14 | 15 | def path = project.repositories.mavenLocal().url 16 | Properties local = new Properties() 17 | local.load(project.rootProject.file('local.properties').newInputStream()) 18 | boolean useLocal = local.get("useLocal", false) 19 | if (useLocal) { 20 | uploadArchives { 21 | repositories { 22 | mavenDeployer { 23 | pom.groupId = "com.github.yjfnypeu" 24 | pom.artifactId = "Speedup" 25 | pom.version = "local" 26 | repository(url : uri(path)) 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /speedup/src/main/groovy/org/component/gradle/ReplacePlugin.groovy: -------------------------------------------------------------------------------- 1 | package org.component.gradle 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | import org.gradle.api.artifacts.Configuration 6 | import org.gradle.api.artifacts.Dependency 7 | import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency 8 | import org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency 9 | import org.gradle.api.logging.LogLevel 10 | 11 | /** 12 | * 动态替换任务插件 13 | * 14 | * @author haoge 15 | */ 16 | class ReplacePlugin implements Plugin{ 17 | 18 | private static Map> cache = new HashMap<>() 19 | private String localRepo 20 | private String[] excludes 21 | 22 | @Override 23 | void apply(Project project) { 24 | RootPlugin.log(LogLevel.DEBUG, "Apply Replace plugin for ${project.path}") 25 | localRepo = project.rootProject.localMaven 26 | excludes = project.rootProject.excludes 27 | 28 | project.configurations.all { Configuration configuration -> 29 | if (configuration.dependencies.size() == 0) { 30 | return 31 | } 32 | 33 | configuration.dependencies.all { dependency -> 34 | if (dependency instanceof DefaultProjectDependency) { 35 | // 过滤Project依赖,并针对excludes进行过滤。被过滤的不参与替换操作 36 | String name = dependency.dependencyProject.path 37 | if (excludes.contains(name)) { 38 | return 39 | } 40 | 41 | // 过滤project所对应的本地依赖不在仓库中的情况。不进行替换 42 | name = name.replaceAll(':','-') 43 | if (!isLocalExist(name)) { 44 | RootPlugin.log(LogLevel.DEBUG, "compile project with name [$name] wasn't be upload to local") 45 | return 46 | } 47 | 48 | /* 49 | * 进行动态替换。 50 | * 1. 从依赖链中移除原来的project 51 | * 2. 读取对应依赖的子依赖。遍历其子依赖,并找出需要被exclude排除(比如被excludes所指出的或者本地仓库中没有对应库的)的本地子依赖 52 | * 3. exclude所有过滤出来的子依赖并替换回project依赖 53 | */ 54 | configuration.dependencies.remove(dependency) 55 | Dependency projectModule = new DefaultExternalModuleDependency("com.local.maven", name, "local") 56 | 57 | def subs = findExcludes(name) 58 | RootPlugin.log(LogLevel.DEBUG, "find sub excludes on [$name] = $subs") 59 | subs.each { 60 | RootPlugin.log(LogLevel.DEBUG, "exclude module $it and replace it with project ${it.replaceAll('-', ':')}") 61 | projectModule.exclude group : 'com.local.maven', module: it 62 | project.dependencies.add(configuration.name, project.project(it.replaceAll('-', ':'))) 63 | } 64 | 65 | configuration.dependencies.add(projectModule) 66 | RootPlugin.log("$project.name Replace dependency $dependency.name with local name [com.local.maven:$name:local] successful!") 67 | } 68 | } 69 | } 70 | } 71 | 72 | private List findExcludes(String name) { 73 | def subExcludes = [] 74 | 75 | if (!isLocalExist(name)) { 76 | subExcludes.add(name) 77 | return subExcludes 78 | } 79 | 80 | def subDependencies = flatDependencies(name) 81 | RootPlugin.log(LogLevel.DEBUG, "find sub dependencies for $name = $subDependencies") 82 | subDependencies.each { 83 | if (excludes.contains(it.replaceAll('-',':'))) { 84 | subExcludes.add(it) 85 | } else { 86 | subExcludes.addAll(findExcludes(it)) 87 | } 88 | } 89 | return subExcludes 90 | } 91 | 92 | private List flatDependencies(String name) { 93 | List list = cache.get(name) 94 | if (list != null) { 95 | return list 96 | } 97 | 98 | list = new ArrayList<>() 99 | try { 100 | File file = new File(localRepo, "com/local/maven/${name}/local/${name}-local.pom") 101 | Node project = new XmlParser().parse(file) 102 | project.dependencies.dependency.each { 103 | if ('com.local.maven' == it.groupId[0].text() 104 | && 'local' == it.version[0].text()) { 105 | String artifactId = it.artifactId[0].text() 106 | list.add(artifactId) 107 | } 108 | } 109 | } catch (Exception e) { 110 | // ignore 111 | RootPlugin.log("parse pom for artifact name $name failed: cause by ${e.message}") 112 | } 113 | cache.put(name, list) 114 | return list 115 | } 116 | 117 | private boolean isLocalExist(String name) { 118 | File repoDir = new File(localRepo, "com/local/maven/$name") 119 | return repoDir.exists() 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /speedup/src/main/groovy/org/component/gradle/RootPlugin.groovy: -------------------------------------------------------------------------------- 1 | package org.component.gradle 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | import org.gradle.api.logging.LogLevel 6 | import org.gradle.api.logging.Logger 7 | 8 | /** 9 | * 加速插件入口. 10 | * 11 | * 加速逻辑主要分为两部分,分别由其余两个插件完成 12 | * 13 | * 1. {@link UploadPlugin} 14 | * 打包上传插件,用于对library project打包发布到本地maven仓库 15 | * 2. {@link ReplacePlugin} 16 | * 动态替换插件,用于进行动态依赖替换。 17 | * 18 | * @author haoge 19 | */ 20 | public class RootPlugin implements Plugin { 21 | 22 | Project root // root project 23 | boolean isAssemble // 运行的是否是assembleXXX任务 24 | boolean isUpload // 运行的是否是插件创建的upload任务(不包括系统定义的uploadArchives) 25 | boolean isUploadAll // 运行的是否是uploadAll任务 26 | static Logger logger 27 | 28 | @Override 29 | void apply(Project project) { 30 | if (project != project.rootProject) { 31 | throw new RuntimeException("You must apply the plugin : 'speedup' on root build.gradle") 32 | } 33 | root = project.rootProject 34 | logger = project.logger 35 | parseTasks(project) 36 | boolean enable 37 | try { 38 | enable = parseLocal() 39 | } catch (Exception e) { 40 | enable = false 41 | } 42 | if (!enable) { 43 | log(LogLevel.ERROR, "plugin 'speedup' is disabled, you can add 'speedup.enable=true' on local.properties to enable Speedup") 44 | return 45 | } 46 | 47 | root.excludes.each { 48 | log("exclude module name $it") 49 | } 50 | 51 | def uploadAll = root.tasks.create(name:'uploadAll', group: 'speedup') 52 | def uploadForClean = root.tasks.create(name:'uploadForClean', group: 'speedup') 53 | uploadAll.dependsOn uploadForClean 54 | 55 | project.subprojects { 56 | it.afterEvaluate { 57 | if (isUpload) { 58 | // 强制自身的version为特殊字符。便于`UploadPlugin`进行匹配修改 59 | it.version = "unspecified" 60 | } 61 | // 对每个project都应用此UploadPlugin. 62 | it.plugins.apply(UploadPlugin) 63 | if (isAssemble || (isUpload && !isUploadAll)) { 64 | // 只针对assemble及upload任务添加动态替换插件 65 | // 排除uploadAll任务。 66 | // assemble任务及upload任务均为根据project依赖链来决定哪些project需要编译的 67 | // 所以对此两种任务。使用动态替换插件。可以有效减少需被编译的module数量。达到打包提速的作用 68 | it.plugins.apply(ReplacePlugin) 69 | } 70 | } 71 | } 72 | } 73 | 74 | private boolean parseLocal() { 75 | // read local.properties 76 | Properties local = new Properties() 77 | local.load(root.file('local.properties').newInputStream()) 78 | File file = new File(local.get("localRepo", '_repo') as String) 79 | String excludeModules = local.get("excludeModules", "") as String 80 | excludeModules = excludeModules.replaceAll(' ','') 81 | root.ext { 82 | excludes = excludeModules.length() == 0 ? [] as String[] : excludeModules.split(',') 83 | localMaven = file.absolutePath 84 | } 85 | 86 | root.subprojects { 87 | repositories { 88 | maven { url file.absolutePath} 89 | } 90 | } 91 | 92 | return Boolean.parseBoolean(local.get("speedup.enable") as String) 93 | } 94 | 95 | // 通知日志打印方法。格式化日志 96 | static void log(LogLevel level = LogLevel.DEBUG, String message) { 97 | logger.log(level, "[Speedup] $message") 98 | } 99 | 100 | // 解析启动任务表。判断是是否含有upload或者assemble任务 101 | private void parseTasks(Project project){ 102 | project.gradle.startParameter.taskNames.each { 103 | if (it.contains("assemble")) { 104 | isAssemble = true 105 | } else if (it.contains('upload') && it != "uploadArchives") { 106 | isUpload = true 107 | } 108 | 109 | if (it == 'uploadAll') { 110 | isUploadAll = true 111 | } 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /speedup/src/main/groovy/org/component/gradle/UploadPlugin.groovy: -------------------------------------------------------------------------------- 1 | package org.component.gradle 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | import org.gradle.api.logging.LogLevel 6 | import org.gradle.api.plugins.MavenPlugin 7 | 8 | /** 9 | * 打包上传插件。 10 | * 11 | * @author haoge 12 | */ 13 | class UploadPlugin implements Plugin{ 14 | 15 | @Override 16 | void apply(Project project) { 17 | def root = project.rootProject 18 | def uploadAll = root.tasks.getByName("uploadAll") 19 | def uploadForClean = root.tasks.getByName("uploadForClean") 20 | String[] excludes = root.excludes 21 | uploadForClean.dependsOn "${project.path}:clean" 22 | 23 | if (project == root 24 | || project.plugins.hasPlugin('com.android.application')) { 25 | return 26 | } 27 | 28 | project.plugins.apply(MavenPlugin) 29 | 30 | project.uploadArchives { 31 | repositories { 32 | mavenDeployer { 33 | pom.groupId = "com.local.maven" 34 | pom.version = "local" 35 | pom.artifactId = project.path.replaceAll(':','-') 36 | repository(url: project.uri(project.rootProject.localMaven)) 37 | 38 | pom.whenConfigured { pom -> 39 | pom.dependencies.forEach { dep -> 40 | if (dep.getVersion() == "unspecified") { 41 | dep.setGroupId("com.local.maven") 42 | dep.setVersion("local") 43 | } 44 | } 45 | } 46 | } 47 | } 48 | } 49 | 50 | // filter exclude modules 51 | if (excludes.contains(project.path)) { 52 | return 53 | } 54 | 55 | // create upload tasks 56 | String name = project.path.replaceAll(":", "") 57 | def upload = project.rootProject.tasks.create(name: "upload$name", group: 'speedup', dependsOn: "${project.path}:uploadArchives") 58 | upload.doLast { 59 | RootPlugin.log(LogLevel.LIFECYCLE, "upload ${project.path} to local maven successful!") 60 | } 61 | 62 | uploadAll.dependsOn upload 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /speedup/src/main/resources/META-INF/gradle-plugins/speedup.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.component.gradle.RootPlugin --------------------------------------------------------------------------------