1/*
2 * Copyright 2012, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 *     * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *     * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *     * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32apply plugin: 'idea'
33
34version = '2.1.2'
35
36if (!('release' in gradle.startParameter.taskNames)) {
37    def versionSuffix
38    try {
39        def git = org.eclipse.jgit.api.Git.open(file('.'))
40        def head = git.getRepository().getRef('HEAD')
41        versionSuffix = head.getObjectId().abbreviate(8).name()
42
43        if (!git.status().call().clean) {
44            versionSuffix += '-dirty'
45        }
46    } catch (Exception) {
47        // In case we can't get the commit for some reason,
48        // just use -dev
49        versionSuffix = 'dev'
50    }
51
52    version += "-${versionSuffix}"
53} else {
54    if (System.env.JDK6_HOME == null && !JavaVersion.current().isJava6()) {
55        throw new InvalidUserDataException("bzzzzzzzt. Release builds must be performed with java 6. " +
56                "Either run gradle with java 6, or define the JDK6_HOME environment variable.")
57    }
58}
59
60// Note: please don't use this. This is strictly for the official releases
61// that are posted on, e.g. the bitbucket download page.
62task release() {
63}
64
65task(install) << {
66    println "Installing version: ${version}"
67}
68
69// The projects that get pushed to maven
70def maven_release_projects = ['smali', 'baksmali', 'dexlib2', 'util']
71
72subprojects {
73    apply plugin: 'java'
74    apply plugin: 'idea'
75
76    if (JavaVersion.current().isJava8Compatible()) {
77        allprojects {
78            tasks.withType(Javadoc) {
79                options.addStringOption('Xdoclint:none', '-quiet')
80            }
81        }
82    }
83
84    if (System.env.JDK6_HOME != null) {
85        sourceCompatibility = 1.6
86        targetCompatibility = 1.6
87
88        tasks.withType(JavaCompile) {
89            doFirst {
90                options.fork = true
91                options.bootClasspath = "$System.env.JDK6_HOME/jre/lib/rt.jar"
92                options.bootClasspath += "$File.pathSeparator$System.env.JDK6_HOME/jre/lib/jsse.jar"
93            }
94        }
95    }
96
97    version = parent.version
98
99    ext {
100        depends = [
101                guava: 'com.google.guava:guava:18.0',
102                findbugs: 'com.google.code.findbugs:jsr305:1.3.9',
103                junit: 'junit:junit:4.6',
104                antlr_runtime: 'org.antlr:antlr-runtime:3.5.2',
105                antlr: 'org.antlr:antlr:3.5.2',
106                stringtemplate: 'org.antlr:stringtemplate:3.2.1',
107                commons_cli: 'commons-cli:commons-cli:1.2',
108                jflex: 'de.jflex:jflex:1.4.3',
109                jflex_plugin: 'co.tomlee.gradle.plugins:gradle-jflex-plugin:0.0.2',
110                proguard_gradle: 'net.sf.proguard:proguard-gradle:5.2.1',
111                dx: 'com.google.android.tools:dx:1.7',
112                gson: 'com.google.code.gson:gson:2.3.1'
113         ]
114    }
115
116    repositories {
117        mavenCentral()
118    }
119
120    if (project.name in maven_release_projects) {
121        apply plugin: 'maven'
122        apply plugin: 'signing'
123
124        group = 'org.smali'
125
126        task javadocJar(type: Jar, dependsOn: javadoc) {
127            classifier = 'javadoc'
128            from 'build/docs/javadoc'
129        }
130
131        task sourcesJar(type: Jar) {
132            classifier = 'sources'
133            from sourceSets.main.allJava
134        }
135
136        artifacts {
137            archives javadocJar
138            archives sourcesJar
139        }
140
141        signing {
142            required { gradle.taskGraph.hasTask('uploadArchives') }
143            sign configurations.archives
144        }
145
146        uploadArchives {
147            repositories.mavenDeployer {
148                configuration = configurations.archives
149
150                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
151
152                if (rootProject.hasProperty('sonatypeUsername') && rootProject.hasProperty('sonatypePassword')) {
153                    repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
154                        authentication(userName: sonatypeUsername, password: sonatypePassword)
155                    }
156                }
157
158                pom.artifactId = project.name
159
160                pom.project {
161                    name project.name
162                    url 'http://smali.org'
163                    packaging 'jar'
164                    licenses {
165                        license {
166                            name 'The BSD 3-Clause License'
167                            url 'http://opensource.org/licenses/BSD-3-Clause'
168                            distribution 'repo'
169                        }
170                    }
171                    scm {
172                        connection 'scm:git:git://github.com/JesusFreke/smali.git'
173                        developerConnection 'scm:git:git@github.com:JesusFreke/smali.git'
174                    }
175                    developers {
176                        developer {
177                            id 'jesusfreke'
178                            name 'Ben Gruver'
179                            email 'jesusfreke@jesusfreke.com'
180                        }
181                    }
182                }
183            }
184        }
185
186        tasks.getByPath(':release').dependsOn(uploadArchives)
187    }
188}
189
190buildscript {
191    repositories {
192        mavenCentral()
193    }
194    dependencies {
195        classpath 'org.eclipse.jgit:org.eclipse.jgit:2.0.0.201206130900-r'
196    }
197}
198
199task wrapper(type: Wrapper) {
200    gradleVersion = '2.11'
201}