build.gradle 5.81 KB
Newer Older
Daniel Wolf's avatar
Daniel Wolf committed
1
2
3
4
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

5
group = 'com.frostnerd.utilskt'
Daniel Wolf's avatar
Daniel Wolf committed
6
version = '3.1.20'
Daniel Wolf's avatar
Daniel Wolf committed
7
ext {
Daniel Wolf's avatar
Daniel Wolf committed
8
    libraryArtifactId = rootProject.name
9
10
}

Daniel Wolf's avatar
Daniel Wolf committed
11
task bumpPatch() {
12
13
14
    dependsOn("bumpPatchVersion")
}

Daniel Wolf's avatar
Daniel Wolf committed
15
task bumpMinor() {
16
17
18
    dependsOn("bumpMinorVersion")
}

Daniel Wolf's avatar
Daniel Wolf committed
19
task bumpMajor() {
20
    dependsOn("bumpMajorVersion")
Daniel Wolf's avatar
Daniel Wolf committed
21
}
Daniel Wolf's avatar
Daniel Wolf committed
22
23
24
25

android {
    compileSdkVersion ANDROID_COMPILE_SDK

Daniel Wolf's avatar
Daniel Wolf committed
26
27
28
29
30
31
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
        kotlinOptions.jvmTarget = "1.8"
    }

Daniel Wolf's avatar
Daniel Wolf committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    defaultConfig {
        minSdkVersion ANDROID_MIN_SDK
        targetSdkVersion ANDROID_COMPILE_SDK
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            consumerProguardFiles 'library-rules.pro', 'release-rules.pro'
        }
    }
    testOptions {
        unitTests.returnDefaultValues = true
        unitTests {
            includeAndroidResources = true
        }
    }
Daniel Wolf's avatar
Daniel Wolf committed
52
53
54
55
56
57
58
59
60
61
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }
62
    compileOptions {
63
        kotlinOptions.freeCompilerArgs += ['-module-name', "$group.$libraryArtifactId"]
Daniel Wolf's avatar
Daniel Wolf committed
64
    }
Daniel Wolf's avatar
Daniel Wolf committed
65
66
}

67
68
69
70
static def compileBinariesLocally() {
    return System.getenv("COMPILE_BINARIES") != null || System.getenv("NEXUS_USER") == null || System.getenv("NEXUS_PASSWORD") == null
}

Daniel Wolf's avatar
Daniel Wolf committed
71
72
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
73
    implementation "androidx.appcompat:appcompat:$APPCOMPAT_VERSION"
Daniel Wolf's avatar
Daniel Wolf committed
74

Daniel Wolf's avatar
Daniel Wolf committed
75
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
76
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$COROUTINE_VERSION"
Daniel Wolf's avatar
Daniel Wolf committed
77

Daniel Wolf's avatar
Daniel Wolf committed
78
    testImplementation 'junit:junit:4.13.2'
Daniel Wolf's avatar
Daniel Wolf committed
79
    //testImplementation "org.robolectric:robolectric:$ROBOELECTRIC_VERSION"
Daniel Wolf's avatar
Daniel Wolf committed
80
81
    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Daniel Wolf's avatar
Daniel Wolf committed
82
83
84
85
86
87
}

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

88
89
90
91
92
task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

93

94
95
96
97
afterEvaluate {
    publishing {
        publications {
            aar(MavenPublication) {
98
99
                groupId group
                version version
100
101
102
103
104
105
                artifactId libraryArtifactId

                artifact("$buildDir/outputs/aar/library-release.aar")
                artifact (sourcesJar) {
                    classifier = 'sources'
                }
Daniel Wolf's avatar
Daniel Wolf committed
106

107
108
109
110
111
112
113
114
115
116
                pom.withXml {
                    def dependenciesNode = asNode().appendNode('dependencies')
                    configurations.implementation.allDependencies.each {
                        if(it.group != null && it.name != null && it.version != null &&
                                it.group != "" && it.name != "" && it.version != "" && it.name != "unspecified"){
                            def dependencyNode = dependenciesNode.appendNode('dependency')
                            dependencyNode.appendNode('groupId', it.group)
                            dependencyNode.appendNode('artifactId', it.name)
                            dependencyNode.appendNode('version', it.version)
                        }
Daniel Wolf's avatar
Daniel Wolf committed
117
118
119
120
                    }
                }
            }
        }
121
122
123
124
125
        repositories {
            maven {
                name 'nexus'
                url "https://nexus.frostnerd.com/repository/libs-release/"
                credentials {
Daniel Wolf's avatar
Daniel Wolf committed
126
127
                    username nexus_user
                    password nexus_password
128
                }}
Daniel Wolf's avatar
Daniel Wolf committed
129
130
131
        }
    }
}
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
publish.dependsOn("assembleRelease", "sourcesJar")


class Version {
    private int major
    private int minor
    private int patch

    Version(String version) {
        def (major, minor, patch) = version.tokenize('.')
        this.major = major.toInteger()
        this.minor = minor.toInteger()
        this.patch = patch.toInteger()
    }

    void bumpMajor() {
        major += 1
        minor = 0
        patch = 0
    }

    void bumpMinor() {
        minor += 1
        patch = 0
    }

    void bumpPatch() {
        patch += 1
    }
    String getName() { "$major.$minor.$patch" }
}

tasks.addRule("Pattern: bump<TYPE>Version") { String taskName ->
    if (taskName.matches("bump(Major|Minor|Patch)Version")) {
        task(taskName) {
            doLast {
                String type = (taskName - 'bump' - 'Version')

                println "Bumping ${type.toLowerCase()} version"
                def parsedVersion = new Version(version)
                parsedVersion."bump$type"()

                println "${version} => ${parsedVersion.name}"

                def updated = buildFile.getText()
                updated = updated.replaceFirst("version\\s*=\\s*'$version'", "version = '${parsedVersion.name}'")
                buildFile.setText(updated)

                exec {
                    commandLine("git", "add", "build.gradle")
                }
                exec {
                    commandLine("git", "commit", "-m", "\"Bump version to ${parsedVersion.name}\"")
                }
                exec {
                    commandLine("git", "tag", "v${parsedVersion.name}")
                }
Daniel Wolf's avatar
Daniel Wolf committed
189
190
191
                exec {
                    commandLine("git", "push")
                }
192
193
194
195
196
197
                exec {
                    commandLine("git", "push", "origin", "v${parsedVersion.name}")
                }
            }
        }
    }
Daniel Wolf's avatar
Daniel Wolf committed
198
}