当前位置:   article > 正文

gradle构建+proguard加密_gradle中springboot 防止反编译

gradle中springboot 防止反编译
构建:build.gradle

加密:library.gradle

libuild.gradle

中文编码---utf-8

  1. apply plugin: 'maven'
  2. apply plugin: 'java'
  3. apply plugin: 'war'
  4. apply plugin: 'eclipse-wtp'
  5. buildDir = "target"
  6. version = '1.0'
  7. sourceCompatibility = 1.8
  8. targetCompatibility = 1.8
  9. //设置文件编码
  10. [compileJava, javadoc, compileTestJava]*.options*.encoding = 'UTF-8'
  11. //执行task时的JVM args上增加参数-Dfile.encoding=UTF-8,否则中文命名的资源打包后,无法解压。
  12. // 设置 WebApp 根目录
  13. webAppDirName = 'WebContent'
  14. //sourceSets.main.java.srcDir 'src' // 设置 Java 源码所在目录
  15. sourceSets {
  16. client{
  17. output.classesDir 'bin/client'
  18. }
  19. common{
  20. output.classesDir 'bin/common'
  21. }
  22. core{
  23. output.classesDir 'bin/core'
  24. }
  25. dev{
  26. output.classesDir 'bin/dev'
  27. }
  28. main{
  29. output.classesDir 'bin/server'
  30. }
  31. modeling{
  32. output.classesDir 'bin/modeling'
  33. }
  34. test{
  35. output.classesDir 'bin/test'
  36. }
  37. }
  38. // 设置 maven 库地址
  39. repositories {
  40. mavenCentral() // 中央库
  41. }
  42. dependencies {
  43. // compile files('lib/common/android/apk/AXMLPrinter2.jar')
  44. // compile files('lib/common/datetime/joda-time-2.3.jar')
  45. // compile files('lib/common/sql/gsp.jar')
  46. // compile files('lib/common/weixin/commons-codec-1.9.jar')
  47. //某个文件夹下面全部依赖
  48. compile fileTree(dir: 'lib/common/', include: '**/*.jar')
  49. }
  50. dependencies {
  51. //providedCompile (在war插件中定义)可以确保 servlet-api 能够在编译时被引用,却不随 web 工程发布(运行时由 Web 容器提供)
  52. providedCompile 'javax.servlet:servlet-api:2.5' // 编译期
  53. providedRuntime 'javax.servlet:jstl:1.2' // 运行时
  54. //testCompile group: 'junit', name: 'junit', version: '4.+'
  55. testCompile (
  56. 'junit:junit:4.11'
  57. )
  58. //compile 中的依赖必然也会被包括在 testCompile 和 runtime
  59. compile (
  60. 'io.netty:netty-all:5.0.0.Alpha1',
  61. 'com.caucho:hessian:4.0.38',
  62. 'redis.clients:jedis:2.4.1',
  63. 'cglib:cglib-nodep:3.1',
  64. 'org.springframework:spring-core:4.1.5.RELEASE',
  65. 'org.springframework:spring-beans:4.1.5.RELEASE',
  66. 'org.springframework:spring-context:4.1.5.RELEASE',
  67. 'com.eaio.uuid:uuid:3.2',
  68. 'org.apache.poi:poi:3.7',
  69. 'org.controlsfx:controlsfx:8.20.8',
  70. 'org.apache.camel:camel-core:2.13.2',
  71. 'com.google.guava:guava:17.0',
  72. 'com.google.code.gson:gson:2.3.1',
  73. 'com.thoughtworks.xstream:xstream:1.4.8',
  74. 'org.codehaus.woodstox:woodstox-core-asl:4.4.1',
  75. 'org.apache.httpcomponents:httpclient:4.3.6',
  76. 'org.apache.httpcomponents:httpcore:4.3.3',
  77. 'commons-fileupload:commons-fileupload:1.3.1',
  78. 'com.alibaba:fastjson:1.2.4',
  79. 'de.jensd:fontawesomefx:8.2' ,
  80. 'com.fasterxml.jackson.core:jackson-databind:2.5.1',
  81. 'com.fasterxml.jackson.core:jackson-core:2.5.1',
  82. 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.5.1',
  83. 'org.codehaus.woodstox:woodstox-core-asl:4.4.1'
  84. )
  85. }
  86. // 设置 Project Facets
  87. import org.gradle.plugins.ide.eclipse.model.Facet
  88. eclipse {
  89. wtp {
  90. facet {
  91. facet name: 'jst.web', type: Facet.FacetType.fixed
  92. facet name: 'wst.jsdt.web', type: Facet.FacetType.fixed
  93. facet name: 'jst.java', type: Facet.FacetType.fixed
  94. facet name: 'jst.web', version: '2.5'
  95. facet name: 'jst.java', version: '1.8'
  96. facet name: 'wst.jsdt.web', version: '1.0'
  97. }
  98. }
  99. }
  100. // 显示当前项目下所有用于 compile 的 jar.
  101. task listJars(description: 'Display all compile jars.') << {
  102. configurations.compile.each { File file -> println file.name }
  103. }
  104. task sourcesJar(type: Jar, dependsOn: classes) {
  105. classifier = 'sources'
  106. baseName = 'miboom'
  107. from sourceSets.main.allSource
  108. //from fileTree('src/main/aidl').include('**/I*.aidl')
  109. }
  110. artifacts {
  111. archives sourcesJar
  112. }
  113. /*****************************************
  114. * 打包
  115. *****************************************/
  116. //jar {
  117. // manifest {
  118. // //attributes 'Main-Class': 'com.javachen.gradle.HelloWorld'
  119. // attributes 'Author': 'zzf'
  120. // }
  121. //}
  122. task jar_dev(type: Jar){
  123. baseName 'miboom_dev'
  124. from("bin/dev")
  125. }
  126. //不dependsOn: classes,gradle编译出错,直接使用eclipse工程的编译输出bin
  127. task jar_mc_client(type: Jar) {
  128. baseName 'mc_client'
  129. from("bin/client")
  130. from("bin/server"){
  131. //除去服务端app、mobile的terminal包及server,模块监听器。
  132. exclude '**/app/**','**/server/**','**/*ModuleListener*','com/miboom/core/framework/terminal/**'
  133. exclude "config/**"
  134. exclude '*.list'
  135. }
  136. }
  137. task jar_mc_common(type: Jar) {
  138. baseName 'mc_common'
  139. from("bin/common"){
  140. exclude '**/*.jj','**/*.jar','**/*.bat','**/*.tpl'
  141. }
  142. }
  143. task jar_ms_common(type: Jar) {
  144. baseName 'ms_common'
  145. from("bin/common"){
  146. exclude '**/*.jj','**/*.jar','**/*.bat','**/*.tpl'
  147. }
  148. }
  149. task jar_mc_core(type: Jar) {
  150. baseName 'mc_core'
  151. from("bin/core"){
  152. exclude '**/readme.txt'
  153. exclude '**/*.javajet'
  154. }
  155. }
  156. task jar_ms_core(type: Jar) {
  157. baseName 'ms_core'
  158. from("bin/core"){
  159. exclude '**/readme.txt'
  160. exclude '**/*.javajet'
  161. }
  162. }
  163. task jar_server(type: Jar) {
  164. baseName 'ms_server'
  165. from("bin/server")
  166. }
  167. task jar_mc_modeling(type: Jar) {
  168. baseName 'mc_modeling'
  169. from("bin/modeling")
  170. }
  171. task jar_ms_modeling(type: Jar) {
  172. baseName 'ms_modeling'
  173. from("bin/modeling")
  174. }
  175. task jar_all(dependsOn: ['jar_mc_client','jar_mc_common','jar_ms_common','jar_mc_core','jar_ms_core','jar_server','jar_mc_modeling','jar_ms_modeling']) {
  176. print "jar all..."
  177. }
  178. war{
  179. dependsOn jar_all
  180. from("$projectDir/src/main/resources") {
  181. include "*.properties"
  182. into("WEB-INF/classes")
  183. }
  184. classpath=classpath - sourceSets.main.output
  185. classpath fileTree(dir:libsDir, include:"${project.name}-${version}.jar")
  186. }
  187. task('jarPath')<<{
  188. configurations.runtime.resolve().each {
  189. print it.toString()+";"
  190. }
  191. println();
  192. }
  193. apply from: 'library.gradle'


library.gradle

+jfxrt.jar包

keywords.txt参考proguard

  1. //
  2. // This Gradle build file illustrates how to process a program
  3. // library, such that it remains usable as a library.
  4. // Usage:
  5. // gradle -b library.gradle proguard
  6. //
  7. // Tell Gradle where to find the ProGuard task.
  8. buildscript {
  9. repositories {
  10. //flatDir dirs: '../../lib'
  11. flatDir dirs: './release/proguard5.2/lib'
  12. // fileTree(dir: './target/libs', include: '**/*.jar')
  13. }
  14. dependencies {
  15. classpath ':proguard'
  16. }
  17. }
  18. // Define a ProGuard task.
  19. task proguard(type: proguard.gradle.ProGuardTask) {
  20. // You should probably import a more compact ProGuard-style configuration
  21. // file for all static settings, but we're specifying them all here, for
  22. // the sake of the example.
  23. //configuration 'configuration.pro'
  24. // Specify the input jars, output jars, and library jars.
  25. // In this case, the input jar is the program library that we want to process.
  26. injars 'target/libs/ms_server-1.0.jar'
  27. injars 'target/libs/ms_modeling-1.0.jar'
  28. injars 'target/libs/ms_core-1.0.jar'
  29. injars 'target/libs/ms_common-1.0.jar'
  30. injars 'target/libs/mc_modeling-1.0.jar'
  31. injars 'target/libs/mc_core-1.0.jar'
  32. injars 'target/libs/mc_common-1.0.jar'
  33. injars 'target/libs/mc_client-1.0.jar'
  34. outjars 'target/libs/obfuscate/'
  35. libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
  36. libraryjars "${System.getProperty('java.home')}/lib/ext/jfxrt.jar"
  37. dontwarn
  38. // Save the obfuscation mapping to a file, so we can de-obfuscate any stack
  39. // traces later on. Keep a fixed source file attribute and all line number
  40. // tables to get line numbers in the stack traces.
  41. // You can comment this out if you're not interested in stack traces.
  42. obfuscationdictionary 'keywords.txt'
  43. classobfuscationdictionary 'keywords.txt'
  44. packageobfuscationdictionary 'keywords.txt'
  45. printmapping 'out.map'
  46. // keepparameternames
  47. renamesourcefileattribute 'SourceFile'
  48. keepattributes 'Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,EnclosingMethod'
  49. // Preserve all annotations.
  50. keepattributes '*Annotation*'
  51. // Preserve all public classes, and their public and protected fields and
  52. // methods.
  53. keep 'public class * { \
  54. public protected *; \
  55. }'
  56. // Preserve all .class method names.
  57. keepclassmembernames 'class * { \
  58. java.lang.Class class$(java.lang.String); \
  59. java.lang.Class class$(java.lang.String, boolean); \
  60. }'
  61. // Preserve all native method names and the names of their classes.
  62. keepclasseswithmembernames includedescriptorclasses:true, 'class * { \
  63. native <methods>; \
  64. }'
  65. // Preserve the special static methods that are required in all enumeration
  66. // classes.
  67. keepclassmembers allowshrinking:true, 'enum * { \
  68. public static **[] values(); \
  69. public static ** valueOf(java.lang.String); \
  70. }'
  71. // Explicitly preserve all serialization members. The Serializable interface
  72. // is only a marker interface, so it wouldn't save them.
  73. // You can comment this out if your library doesn't use serialization.
  74. // If your code contains serializable classes that have to be backward
  75. // compatible, please refer to the manual.
  76. keepclassmembers 'class * implements java.io.Serializable { \
  77. static final long serialVersionUID; \
  78. static final java.io.ObjectStreamField[] serialPersistentFields; \
  79. private void writeObject(java.io.ObjectOutputStream); \
  80. private void readObject(java.io.ObjectInputStream); \
  81. java.lang.Object writeReplace(); \
  82. java.lang.Object readResolve(); \
  83. }'
  84. // Your library may contain more items that need to be preserved;
  85. // typically classes that are dynamically created using Class.forName:
  86. // keep 'public class mypackage.MyClass'
  87. // keep 'public interface mypackage.MyInterface'
  88. // keep 'public class * implements mypackage.MyInterface'
  89. }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/1015803
推荐阅读
相关标签
  

闽ICP备14008679号