build.gradle 5.49 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'

Daniel Wolf's avatar
Daniel Wolf committed
5
group = 'com.frostnerd.utils'
6
version = '1.0.5'
Daniel Wolf's avatar
Daniel Wolf committed
7
ext {
Daniel Wolf's avatar
Daniel Wolf committed
8
    libraryArtifactId = rootProject.name
9
10
11
12
13
14
15
16
17
18
19
20
}

task bumpPatch(type: Exec) {
    dependsOn("bumpPatchVersion")
}

task bumpMinor(type: Exec) {
    dependsOn("bumpMinorVersion")
}

task bumpMajor(type: Exec) {
    dependsOn("bumpMajorVersion")
Daniel Wolf's avatar
Daniel Wolf committed
21
22
}

Daniel Wolf's avatar
Daniel Wolf committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
android {
    compileSdkVersion ANDROID_COMPILE_SDK

    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
46
47
48
49
50
51
52
53
54
    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'
55
56
    }
    compileOptions {
57
        kotlinOptions.freeCompilerArgs += ['-module-name', "$group.$libraryArtifactId"]
Daniel Wolf's avatar
Daniel Wolf committed
58
    }
Daniel Wolf's avatar
Daniel Wolf committed
59
60
}

61
62
63
64
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
65
66
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
67
    implementation "androidx.appcompat:appcompat:$APPCOMPAT_VERSION"
Daniel Wolf's avatar
Daniel Wolf committed
68

Daniel Wolf's avatar
Daniel Wolf committed
69
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
Daniel Wolf's avatar
Daniel Wolf committed
70

Daniel Wolf's avatar
Daniel Wolf committed
71
    testImplementation 'junit:junit:4.13.2'
Daniel Wolf's avatar
Daniel Wolf committed
72
    //testImplementation "org.robolectric:robolectric:$ROBOELECTRIC_VERSION"
Daniel Wolf's avatar
Daniel Wolf committed
73
74
    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Daniel Wolf's avatar
Daniel Wolf committed
75
76
77
78
79
80
}

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

81
82
83
84
85
task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

86

87
88
89
90
afterEvaluate {
    publishing {
        publications {
            aar(MavenPublication) {
91
92
                groupId group
                version version
93
94
95
96
97
98
                artifactId libraryArtifactId

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

100
101
102
103
104
105
106
107
108
109
                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
110
111
112
113
                    }
                }
            }
        }
114
115
116
117
118
        repositories {
            maven {
                name 'nexus'
                url "https://nexus.frostnerd.com/repository/libs-release/"
                credentials {
Daniel Wolf's avatar
Daniel Wolf committed
119
120
                    username nexus_user
                    password nexus_password
121
                }}
Daniel Wolf's avatar
Daniel Wolf committed
122
123
        }
    }
Daniel Wolf's avatar
Daniel Wolf committed
124
}
125
126
127
128
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}")
                }
                exec {
                    commandLine("git", "push", "origin", "v${parsedVersion.name}")
                }
            }
        }
    }
}