Advertisement
df1412

gradle-script

Sep 20th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.99 KB | None | 0 0
  1. import java.util.regex.Pattern
  2.  
  3. apply plugin: 'com.android.library'
  4.  
  5. buildscript {
  6.     repositories {
  7.         jcenter()
  8.     }
  9.     dependencies {
  10.         classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
  11.         classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
  12.     }
  13. }
  14.  
  15. repositories {
  16.     jcenter()
  17. }
  18.  
  19. apply plugin: 'com.jfrog.bintray'
  20. apply plugin: 'com.github.dcendents.android-maven'
  21. apply plugin: 'maven'
  22. apply plugin: 'maven-publish'
  23. //apply plugin: 'java'
  24.  
  25. group = '<group_id>'
  26. version = versionName
  27. def siteUrl = '<siteUrl>'   // Homepage URL of the library
  28. def gitUrl = '<gitUrl>' // Git repository URL
  29.  
  30. android {
  31.     compileSdkVersion 24
  32.     buildToolsVersion "23.0.3"
  33.  
  34.     defaultConfig {
  35.         minSdkVersion 16
  36.         targetSdkVersion 23
  37.         versionCode versionCode
  38.         versionName versionName
  39.         renderscriptTargetApi 19
  40.         renderscriptSupportModeEnabled true
  41.     }
  42.     buildTypes {
  43.         release {
  44.             minifyEnabled false
  45.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  46.         }
  47.     }
  48. }
  49.  
  50. publishing {
  51.     publications {
  52.         AndroidUtilities(MavenPublication) {
  53.             //from components.java
  54.             groupId group
  55.             artifactId 'androidutilities'
  56.             version versionName
  57.         }
  58.     }
  59. }
  60.  
  61. task incrementVersionCode << {
  62.     println(":incrementVersionCode - Incrementing Version Code...")
  63.     def manifestFile = file("src/main/AndroidManifest.xml")
  64.     def propertiesFile = file("gradle.properties")
  65.     def patternVersionCode = Pattern.compile("versionCode=\"?(\\d+)\"?")
  66.     def manifestText = manifestFile.getText()
  67.     def propertiesText = propertiesFile.getText()
  68.     def manifestMatcherVersionCode = patternVersionCode.matcher(manifestText)
  69.     def propertiesMatcherVersionCode = patternVersionCode.matcher(propertiesText)
  70.     def mVersionCode = 0
  71.     if (propertiesMatcherVersionCode.find()) {
  72.         mVersionCode = Integer.parseInt(propertiesMatcherVersionCode.group(1))
  73.     }
  74.     def mNextVersionCode = mVersionCode + 1
  75.     def manifestContent = manifestMatcherVersionCode.replaceAll("versionName=\"" + mNextVersionName + "\"")
  76.     def propertiesContent = propertiesMatcherVersionCode.replaceAll("versionName=" + mNextVersionName)
  77.     println(":incrementVersionCode - current versionCode=" + mVersionCode);
  78.     println(":incrementVersionCode - next versionCode=" + mNextVersionCode);
  79.     manifestFile.write(manifestContent)
  80.     propertiesFile.write(propertiesContent)
  81. }
  82.  
  83. task incrementVersionName << {
  84.     println(":incrementVersionName - Incrementing Version Name...")
  85.     def manifestFile = file("src/main/AndroidManifest.xml")
  86.     def propertiesFile = file("gradle.properties")
  87.     def patternVersionNumber = Pattern.compile("versionName=\"?(\\d+)\\.(\\d+)\\.(\\d+)\"?")
  88.     def manifestText = manifestFile.getText()
  89.     def propertiesText = propertiesFile.getText()
  90.     def manifestMatcherVersionNumber = patternVersionNumber.matcher(manifestText)
  91.     def propertiesMatcherVersionNumber = patternVersionNumber.matcher(propertiesText)
  92.     def majorVersion = 0
  93.     def minorVersion = 0
  94.     def pointVersion = 0
  95.     if (propertiesMatcherVersionNumber.find()) {
  96.         majorVersion = Integer.parseInt(propertiesMatcherVersionNumber.group(1))
  97.         minorVersion = Integer.parseInt(propertiesMatcherVersionNumber.group(2))
  98.         pointVersion = Integer.parseInt(propertiesMatcherVersionNumber.group(3))
  99.     }
  100.     def mVersionName = majorVersion + "." + minorVersion + "." + pointVersion
  101.     def mNextVersionName = majorVersion + "." + minorVersion + "." + (pointVersion + 1)
  102.     def manifestContent = manifestMatcherVersionNumber.replaceAll("versionName=\"" + mNextVersionName + "\"")
  103.     def propertiesContent = propertiesMatcherVersionNumber.replaceAll("versionName=" + mNextVersionName)
  104.     println(":incrementVersionName - current versionName=" + mVersionName);
  105.     println(":incrementVersionName - new versionName=" + mNextVersionName);
  106.     manifestFile.write(manifestContent)
  107.     propertiesFile.write(propertiesContent)
  108. }
  109.  
  110. task release << {
  111.     println(":release - Build and Version Increment")
  112. }
  113.  
  114. task debug << {
  115.     println(":debug - Build")
  116. }
  117.  
  118. tasks.whenTaskAdded { task ->
  119.     //println("- " + task.name)
  120.     if (task.name == 'bundleRelease'){
  121.         task.dependsOn 'generateDebugBuildConfig'
  122.     }
  123.     if (task.name == 'generateDebugBuildConfig'){
  124.         //task.dependsOn 'incrementVersionName'
  125.     }
  126.     if (task.name == 'generatePomFileForAndroidUtilitiesPublication'){
  127.         //task.dependsOn 'generateDebugBuildConfig'
  128.         //task.dependsOn 'incrementVersionName'
  129.     }
  130. }
  131.  
  132. dependencies {
  133.     compile fileTree(dir: 'libs', include: ['*.jar'])
  134.     compile 'com.google.api-client:google-api-client-android:1.18.0-rc' exclude module: 'httpclient'
  135.     compile 'com.android.support:appcompat-v7:24.0.0-beta1'
  136.     compile 'com.android.support:recyclerview-v7:24.0.0-beta1'
  137.     compile 'com.squareup.okhttp3:okhttp:3.2.0'
  138.     compile 'com.github.franmontiel:PersistentCookieJar:v0.9.3'
  139.     compile 'com.github.bumptech.glide:glide:3.7.0'
  140.     compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
  141.     compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
  142.     compile 'de.greenrobot:greendao:1.3.7'
  143.     compile 'de.greenrobot:eventbus:2.4.0'
  144.     compile 'org.lucasr.twowayview:twowayview:0.1.4'
  145.     compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'
  146.     compile 'com.baoyz.swipemenulistview:library:1.3.0'
  147.     compile 'com.eftimoff:android-viewpager-transformers:1.0.1@aar'
  148.     compile 'net.danlew:android.joda:2.9.3'
  149.     compile 'com.jeremyfeinstein.slidingmenu:library:1.3@aar'
  150.     compile 'com.google.android.gms:play-services:9.4.0'
  151.     compile 'com.google.android.gms:play-services-ads:9.4.0'
  152.     compile 'com.google.android.gms:play-services-auth:9.4.0'
  153.     compile 'org.jsoup:jsoup:1.9.2'
  154.     compile "com.google.firebase:firebase-messaging:9.0.0"
  155. }
  156.  
  157. install {
  158.     repositories.mavenInstaller {
  159.         // This generates POM.xml with proper parameters
  160.         pom {
  161.             project {
  162.                 packaging 'aar'
  163.  
  164.                 // Add your description here
  165.                 name 'Android-Utilities' // TODO
  166.                 description = 'Collection of common Android Utilities to help create new project' // TODO
  167.                 url siteUrl
  168.  
  169.                 // Set your license
  170.                 licenses {
  171.                     license {
  172.                         name 'The Apache Software License, Version 2.0'
  173.                         url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  174.                     }
  175.                 }
  176.                 developers {
  177.                     developer {
  178.                         id '<userid>' // TODO
  179.                         name '<name>' // TODO
  180.                         email '<email>' // TODO
  181.                     }
  182.                 }
  183.                 scm {
  184.                     connection gitUrl
  185.                     developerConnection gitUrl
  186.                     url siteUrl
  187.                 }
  188.             }
  189.         }
  190.     }
  191. }
  192.  
  193. task sourcesJar(type: Jar) {
  194.     from android.sourceSets.main.java.srcDirs
  195.     classifier = 'sources'
  196. }
  197. task javadoc(type: Javadoc) {
  198.     source = android.sourceSets.main.java.srcDirs
  199.     classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
  200. }
  201. task javadocJar(type: Jar, dependsOn: javadoc) {
  202.     classifier = 'javadoc'
  203.     from javadoc.destinationDir
  204. }
  205. artifacts {
  206.     archives javadocJar
  207.     archives sourcesJar
  208. }
  209.  
  210. Properties project_properties = new Properties()
  211. project_properties.load(project.rootProject.file('local.properties').newDataInputStream())
  212.  
  213. bintray {
  214.     user = project_properties.getProperty('bintray.user');
  215.     key = project_properties.getProperty('bintray.apikey');
  216.     //publications = ['AndroidUtilities'] //When uploading configuration files
  217.     // - OR -
  218.     configurations = ['archives'] //When uploading configuration files
  219.     // - AND/OR -
  220.     //filesSpec { //When uploading any arbitrary files ('filesSpec' is a standard Gradle CopySpec)
  221.     //    from 'arbitrary-files'
  222.     //    into 'standalone_files/level1'
  223.     //    rename '(.+)\\.(.+)', '$1-suffix.$2'
  224.     //}
  225.     dryRun = false //[Default: false] Whether to run this as dry-run, without deploying
  226.     publish = true //[Default: false] Whether version should be auto published after an upload
  227.     override = false //[Default: false] Whether to override version artifacts already published
  228.     //Package configuration. The plugin will use the repo and name properties to check if the package already exists. In that case, there's no need to configure the other package properties (like userOrg, desc, etc).
  229.     pkg {
  230.         repo = 'androidutilities'
  231.         name = 'Android-Utilities'
  232.         userOrg = user
  233.         licenses = ['Apache-2.0']
  234.         websiteUrl = siteUrl
  235.         issueTrackerUrl = siteUrl + '/issues'
  236.         vcsUrl = gitUrl
  237.         labels = ['android', 'utilities']
  238.         publicDownloadNumbers = true
  239.         attributes= ['a': ['ay1', 'ay2'], 'b': ['bee'], c: 'cee'] //Optional package-level attributes
  240.  
  241.         githubRepo = '<repo>' //Optional Github repository
  242.         githubReleaseNotesFile = 'README.md' //Optional Github readme file
  243.  
  244.         dryRun = false //[Default: false] Whether to run this as dry-run, without deploying
  245.         publish = true //[Default: false] Whether version should be auto published after an upload
  246.         override = true //[Default: false] Whether to override version artifacts already published
  247.  
  248.         version {
  249.             name = versionName //Bintray logical version name
  250.             desc = versionName //Optional - Version-specific description'
  251.             released  = new java.util.Date() //Optional - Date of the version release. 2 possible values: date in the format of 'yyyy-MM-dd'T'HH:mm:ss.SSSZZ' OR a java.util.Date instance
  252.             vcsTag = versionName
  253.             attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin'] //Optional version-level attributes
  254.  
  255.             //Optional configuration for GPG signing
  256.             gpg {
  257.                 sign = true //Determines whether to GPG sign the files. The default is false
  258.                 passphrase = '<passphrase>' //Optional. The passphrase for GPG signing'
  259.             }
  260.             //Optional configuration for Maven Central sync of the version
  261.             mavenCentralSync {
  262.                 sync = true //[Default: true] Determines whether to sync the version to Maven Central.
  263.                 user = '<user>' //OSS user token: mandatory
  264.                 password = '<passphrase>' //OSS user password: mandatory
  265.                 close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
  266.             }
  267.         }
  268.     }
  269. }
  270.  
  271. task wrapper(type: Wrapper) {
  272.     gradleVersion = '2.4'
  273. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement