Skip to content

Commit

Permalink
Introduce build conventions
Browse files Browse the repository at this point in the history
This helps cleaning up and maintaining Gradle
  • Loading branch information
ThexXTURBOXx committed Dec 11, 2023
1 parent bdbc641 commit a74597e
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 154 deletions.
131 changes: 4 additions & 127 deletions build.gradle
Expand Up @@ -3,22 +3,16 @@ plugins {
id "base"
id "signing"
id "io.github.gradle-nexus.publish-plugin" version "2.0.0-rc-1"
id "dex2jar.build-conventions"
}

ext.antlr3Version = '3.5.3'
ext.antlr4Version = '4.9.3' // Newer versions only for Java 11+
ext.asmVersion = '9.6'
ext.baksmaliVersion = '3.0.3'
ext.commonsCompressVersion = '1.25.0'
ext.jUnitVersion = '5.10.1'
ext.jUnitPlatformVersion = '1.10.1'
ext.r8Version = '4.0.63' // Newer versions only for Java 11+
description = 'Supermodule for dex2jar'

nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri(Meta.release))
snapshotRepositoryUrl.set(uri(Meta.snapshot))
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
var ossrhUsername = providers.environmentVariable("OSSRH_USERNAME")
var ossrhPassword = providers.environmentVariable("OSSRH_PASSWORD")
if (ossrhUsername.present && ossrhPassword.present) {
Expand All @@ -29,115 +23,6 @@ nexusPublishing {
}
}

allprojects {
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'signing'

group = 'de.femtopedia.dex2jar'
version = project.findProperty('version')
version = version == null || version == 'unspecified' ? '2.4-SNAPSHOT' : version

repositories {
mavenCentral()
google()
}

java {
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
withJavadocJar()
}

javadoc {
options.encoding = 'UTF-8'
}

dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
testImplementation "org.junit.jupiter:junit-jupiter:${project.property('jUnitVersion')}"
testRuntimeOnly("org.junit.platform:junit-platform-launcher:${project.property('jUnitPlatformVersion')}")
}

[compileJava, compileTestJava]*.options.collect { options -> options.encoding = 'UTF-8' }

test {
useJUnitPlatform()

systemProperty 'junit.jupiter.execution.parallel.enabled', true
systemProperty 'junit.jupiter.execution.parallel.mode.default', 'concurrent'
}
}

subprojects {
// Cache list of tasks
project.getAllTasks(true)
}

allprojects {
signing {
var signingKey = providers.environmentVariable("GPG_SIGNING_KEY")
var signingPassphrase = providers.environmentVariable("GPG_SIGNING_PASSPHRASE")
if (signingKey.present && signingPassphrase.present) {
useInMemoryPgpKeys(signingKey.get(), signingPassphrase.get())
sign publishing.publications
}
}

publishing {
publications {
mavenJava(MavenPublication) {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
if (tasks.findByName("shadowJar") == null)
from(components.java)
else {
artifact(tasks.named("shadowJar"))
artifact(tasks.named("sourcesJar"))
artifact(tasks.named("javadocJar"))
}
pom {
name.set(project.name)
description.set(Meta.desc)
url.set("https://${Meta.githubRepo}")
licenses {
license {
name.set(Meta.license)
url.set("https://opensource.org/licenses/Apache-2.0")
}
}
developers {
developer {
id.set("pxb1988")
name.set("Bob Pan")
}
developer {
id.set("ThexXTURBOXx")
name.set("Nico Mexis")
}
}
scm {
url.set("https://${Meta.githubRepo}.git")
connection.set("scm:git:git://${Meta.githubRepo}.git")
developerConnection.set("scm:git:git://${Meta.githubRepo}.git")
}
issueManagement {
url.set("https://${Meta.githubRepo}/issues")
}
}
}
}
}

// Workaround for https://github.com/gradle/gradle/issues/820
configurations {
api {
extendsFrom = extendsFrom.findAll { it != configurations.antlr }
}
}
}

application {
mainClass = "com.googlecode.dex2jar.tools.Dex2jarCmd"
}
Expand All @@ -158,11 +43,3 @@ dependencies {
api(project(":dex-translator"))
api(project(":dex-writer"))
}

class Meta {
public static final var desc = "Tools to work with android .dex and java .class files"
public static final var license = "Apache-2.0"
public static final var githubRepo = "github.com/ThexXTURBOXx/dex2jar"
public static final var release = "https://s01.oss.sonatype.org/service/local/"
public static final var snapshot = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
}
3 changes: 3 additions & 0 deletions buildSrc/build.gradle
@@ -0,0 +1,3 @@
plugins {
id 'groovy-gradle-plugin'
}
123 changes: 123 additions & 0 deletions buildSrc/src/main/groovy/dex2jar.build-conventions.gradle
@@ -0,0 +1,123 @@
plugins {
id 'java-library'
id 'maven-publish'
id 'signing'
}

ext.antlr3Version = '3.5.3'
ext.antlr4Version = '4.9.3' // Newer versions only for Java 11+
ext.asmVersion = '9.6'
ext.baksmaliVersion = '3.0.3'
ext.commonsCompressVersion = '1.25.0'
ext.jUnitVersion = '5.10.1'
ext.jUnitPlatformVersion = '1.10.1'
ext.r8Version = '4.0.63' // Newer versions only for Java 11+

group = 'de.femtopedia.dex2jar'
version = project.findProperty('version')
version = version == null || version == 'unspecified' ? '2.4-SNAPSHOT' : version

repositories {
mavenCentral()
google()
}

java {
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
withJavadocJar()
}

javadoc {
options.encoding = 'UTF-8'
options.source = '8'
}

dependencies {
testImplementation "org.junit.jupiter:junit-jupiter:${project.property('jUnitVersion')}"
testRuntimeOnly("org.junit.platform:junit-platform-launcher:${project.property('jUnitPlatformVersion')}")
}

[compileJava, compileTestJava]*.options.collect { options -> options.encoding = 'UTF-8' }

signing {
var signingKey = providers.environmentVariable("GPG_SIGNING_KEY")
var signingPassphrase = providers.environmentVariable("GPG_SIGNING_PASSPHRASE")
if (signingKey.present && signingPassphrase.present) {
useInMemoryPgpKeys(signingKey.get(), signingPassphrase.get())
sign publishing.publications
}
}

// Workaround for https://github.com/gradle/gradle/issues/820
configurations {
api {
extendsFrom = extendsFrom.findAll { it != configurations.antlr }
}
}

// Workaround from https://github.com/gradle/gradle/issues/19555#issuecomment-1593252653
try {
sourceSets.configureEach {
var generateGrammarSource = tasks.named(getTaskName("generate", "GrammarSource"))
java.srcDir(generateGrammarSource.map { files() })
}
} catch (Throwable ignored) {
}

test {
dependsOn ':d2j-external:shadowJar'
useJUnitPlatform()
systemProperty 'junit.jupiter.execution.parallel.enabled', true
systemProperty 'junit.jupiter.execution.parallel.mode.default', 'concurrent'
}

afterEvaluate {
publishing {
publications {
mavenJava(MavenPublication) {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
if (project.name == "d2j-external") {
artifact(shadowJar)
artifact(sourcesJar)
artifact(javadocJar)
} else {
from(components.java)
}
pom {
name.set(project.name)
description.set(project.description)
url.set("https://github.com/ThexXTURBOXx/dex2jar")
licenses {
license {
name.set('The Apache License, Version 2.0')
url.set('https://www.apache.org/licenses/LICENSE-2.0.txt')
}
}
developers {
developer {
id.set("pxb1988")
name.set("Bob Pan")
email.set("pxb1988@gmail.com")
}
developer {
id.set("ThexXTURBOXx")
name.set("Nico Mexis")
email.set("nico.mexis@kabelmail.de")
}
}
scm {
url.set("https://github.com/ThexXTURBOXx/dex2jar.git")
connection.set("scm:git:git://github.com/ThexXTURBOXx/dex2jar.git")
developerConnection.set("scm:git:git://github.com/ThexXTURBOXx/dex2jar.git")
}
issueManagement {
url.set("https://github.com/ThexXTURBOXx/dex2jar/issues")
}
}
}
}
}
}
6 changes: 5 additions & 1 deletion d2j-base-cmd/build.gradle
@@ -1,4 +1,8 @@
description = 'a simple cmd parser'
plugins {
id "dex2jar.build-conventions"
}

description = "Simple cmd parser for dex2jar"

dependencies {
api project(':d2j-external')
Expand Down
5 changes: 2 additions & 3 deletions d2j-external/build.gradle
@@ -1,10 +1,9 @@
plugins {
id "com.github.johnrengelman.shadow" version "8.1.1"
id "dex2jar.build-conventions"
}

apply plugin: 'com.github.johnrengelman.shadow'

description = 'Module for including external libraries'
description = "External and fixed libraries for dex2jar"

dependencies {
api fileTree(dir: '../libs', include: '*.jar')
Expand Down
13 changes: 6 additions & 7 deletions d2j-jasmin/build.gradle
@@ -1,4 +1,9 @@
apply plugin: 'antlr'
plugins {
id "antlr"
id "dex2jar.build-conventions"
}

description = "Jasmin support for dex2jar"

dependencies {
api(group: 'org.antlr', name: 'antlr-runtime', version: project.property('antlr3Version')) {
Expand All @@ -17,9 +22,3 @@ dependencies {
}

sourceSets.main.antlr.srcDirs = ['src/main/antlr3']

// From https://github.com/gradle/gradle/issues/19555#issuecomment-1593252653
sourceSets.configureEach {
var generateGrammarSource = tasks.named(getTaskName("generate", "GrammarSource"))
java.srcDir(generateGrammarSource.map { files() })
}
13 changes: 6 additions & 7 deletions d2j-smali/build.gradle
@@ -1,4 +1,9 @@
apply plugin: 'antlr'
plugins {
id "antlr"
id "dex2jar.build-conventions"
}

description = "Smali support for dex2jar"

dependencies {
api "org.antlr:antlr4-runtime:${project.property('antlr4Version')}"
Expand All @@ -18,9 +23,3 @@ sourceSets {
test.output.resourcesDir = "build/classes/test"
main.antlr.srcDirs = ['src/main/antlr4']
}

// From https://github.com/gradle/gradle/issues/19555#issuecomment-1593252653
sourceSets.configureEach {
var generateGrammarSource = tasks.named(getTaskName("generate", "GrammarSource"))
java.srcDir(generateGrammarSource.map { files() })
}
6 changes: 5 additions & 1 deletion dex-ir/build.gradle
@@ -1,4 +1,8 @@
description = 'Dex Translator'
plugins {
id "dex2jar.build-conventions"
}

description = 'Intermediate representations for dex2jar'

dependencies {
api project(':dex-reader-api')
Expand Down
6 changes: 5 additions & 1 deletion dex-reader-api/build.gradle
@@ -1,4 +1,8 @@
description = 'Dex Reader API'
plugins {
id "dex2jar.build-conventions"
}

description = 'Dex/Dalvik reader API for dex2jar'

dependencies {
api project(':d2j-external')
Expand Down
6 changes: 5 additions & 1 deletion dex-reader/build.gradle
@@ -1,4 +1,8 @@
description = 'Dex Reader'
plugins {
id "dex2jar.build-conventions"
}

description = 'Dex/Dalvik reader for dex2jar'

dependencies {
api project(':dex-reader-api')
Expand Down

0 comments on commit a74597e

Please sign in to comment.