build.gradle 3.9 KB
Newer Older
S
Skylot 已提交
1
plugins {
S
Skylot 已提交
2
	id 'com.github.ben-manes.versions' version '0.39.0'
S
Skylot 已提交
3
	id 'com.diffplug.spotless' version '6.0.2'
S
Skylot 已提交
4 5
}

6
ext.jadxVersion = System.getenv('JADX_VERSION') ?: "dev"
S
Skylot 已提交
7
version = jadxVersion
8
println("jadx version: ${jadxVersion}")
S
Skylot 已提交
9

10
allprojects {
11
	apply plugin: 'java'
12
	apply plugin: 'checkstyle'
13 14 15

	version = jadxVersion

16 17 18
	sourceCompatibility = JavaVersion.VERSION_1_8
	targetCompatibility = JavaVersion.VERSION_1_8

19 20 21 22 23 24 25 26 27 28 29
	compileJava {
		options.encoding = "UTF-8"
	}

	jar {
		manifest {
			mainAttributes('jadx-version': jadxVersion)
		}
	}

	dependencies {
S
Skylot 已提交
30
		implementation 'org.slf4j:slf4j-api:1.7.32'
S
Skylot 已提交
31
		compileOnly 'org.jetbrains:annotations:23.0.0'
32

S
Skylot 已提交
33
		testImplementation 'ch.qos.logback:logback-classic:1.2.8'
34
		testImplementation 'org.hamcrest:hamcrest-library:2.2'
S
Skylot 已提交
35
		testImplementation 'org.mockito:mockito-core:4.1.0'
S
Skylot 已提交
36
		testImplementation 'org.assertj:assertj-core:3.21.0'
37

S
Skylot 已提交
38 39
		testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
		testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
40

41
		testImplementation 'org.eclipse.jdt.core.compiler:ecj:4.6.1'
S
Skylot 已提交
42
		testCompileOnly 'org.jetbrains:annotations:23.0.0'
43 44 45 46 47 48 49 50 51 52 53
	}

	test {
		useJUnitPlatform()
	}

	repositories {
		mavenLocal()
		mavenCentral()
		google()
	}
54 55
}

56 57 58 59 60 61
spotless {
	java {
		target fileTree(rootDir).matching {
			include 'jadx-cli/src/**/java/**/*.java'
			include 'jadx-core/src/**/java/**/*.java'
			include 'jadx-gui/src/**/java/**/*.java'
62
			include 'jadx-plugins/**/java/**/*.java'
63 64 65 66
		}

		importOrderFile 'config/code-formatter/eclipse.importorder'
		eclipse().configFile 'config/code-formatter/eclipse.xml'
67 68 69 70 71 72
		if (JavaVersion.current() < JavaVersion.VERSION_16) {
			removeUnusedImports()
		} else {
			// google-format broken on java 16 (https://github.com/diffplug/spotless/issues/834)
			println('Warning! Unused imports remove is disabled for Java 16')
		}
73

74
		lineEndings(com.diffplug.spotless.LineEnding.UNIX)
75 76 77 78 79 80
		encoding("UTF-8")
		trimTrailingWhitespace()
		endWithNewline()
	}
	format 'misc', {
		target '**/*.gradle', '**/*.md', '**/*.xml', '**/.gitignore', '**/.properties'
81
		targetExclude ".gradle/**", ".idea/**", "*/build/**"
82

83
		lineEndings(com.diffplug.spotless.LineEnding.UNIX)
84 85 86 87
		encoding("UTF-8")
		trimTrailingWhitespace()
		endWithNewline()
	}
S
Skylot 已提交
88 89
}

90 91 92 93 94 95 96 97 98 99
dependencyUpdates {
	resolutionStrategy {
		componentSelection { rules ->
			rules.all { ComponentSelection selection ->
				boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm', 'atlassian'].any { qualifier ->
					selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
				}
				if (rejected) {
					selection.reject('Release candidate')
				}
100 101 102
			}
		}
	}
S
Skylot 已提交
103 104
}

105 106 107 108
task copyArtifacts(type: Copy) {
	from tasks.getByPath(":jadx-cli:installDist")
	from tasks.getByPath(":jadx-gui:installDist")
	into layout.buildDirectory.dir("jadx")
109
	duplicatesStrategy = DuplicatesStrategy.EXCLUDE
S
Skylot 已提交
110 111
}

112 113
task pack(type: Zip) {
	from copyArtifacts
114
	archiveFileName = "jadx-${jadxVersion}.zip"
115
	destinationDirectory = layout.buildDirectory
S
Skylot 已提交
116 117
}

118
task copyExe(type: Copy) {
119 120
	group 'jadx'
	description = 'Copy exe to build dir'
121 122 123
	mustRunAfter pack // not needed, but gradle throws warning because of same output dir

	from tasks.getByPath('jadx-gui:createExe')
124
	include '*.exe'
125
	into layout.buildDirectory
126
	duplicatesStrategy = DuplicatesStrategy.EXCLUDE
S
Skylot 已提交
127 128
}

S
Skylot 已提交
129 130 131 132 133 134 135 136 137 138
task distWinBundle(type: Copy, dependsOn: 'jadx-gui:distWinWithJre') {
	group 'jadx'
	description = 'Copy bundle to build dir'
	destinationDir buildDir
	from(tasks.getByPath('jadx-gui:distWinWithJre').outputs) {
		include '*.zip'
	}
	duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

139
task dist {
140 141
	group 'jadx'
	description = 'Build jadx distribution zip'
142 143

	dependsOn(pack)
144 145 146

	OperatingSystem os = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentOperatingSystem;
	if (os.isWindows()) {
S
Skylot 已提交
147 148 149 150 151 152
		if (project.hasProperty("bundleJRE")) {
			println("Build win bundle with JRE")
			dependsOn('distWinBundle')
		} else {
			dependsOn('copyExe')
		}
S
Skylot 已提交
153 154 155
	}
}

S
Skylot 已提交
156
task cleanBuildDir(type: Delete) {
157 158
	group 'jadx'
	delete buildDir
S
Skylot 已提交
159 160
}

S
Skylot 已提交
161
clean.dependsOn(cleanBuildDir)