提交 480447dd 编写于 作者: B Blankj

see 03/27 log

上级 d21758b0
* `20/03/27` [opt] publish.gradle
* `20/01/17` [upd] Leak Canary to v2.1.
* `19/11/30` [add] Publish bus plugin v2.4. Publish api plugin v1.2.
* `19/11/28` [add] Publish v1.26.0.
......
......@@ -12,12 +12,12 @@ gradlePlugin {
plugins {
readmeCore {
id = 'readme-core'
implementationClass = 'com.blankj.plugin.ReadmeCorePlugin'
implementationClass = 'com.blankj.plugin.readme.ReadmeCorePlugin'
}
readmeSub {
id = 'readme-sub'
implementationClass = 'com.blankj.plugin.ReadmeSubPlugin'
implementationClass = 'com.blankj.plugin.readme.ReadmeSubPlugin'
}
}
}
......
......@@ -15,7 +15,7 @@ class Config {
static minSdkVersion = 14
static targetSdkVersion = 29
static versionCode = 1_026_001
static versionName = '1.26.1-alpha8'// E.g. 1.9.72 => 1,009,072
static versionName = '1.26.1-r5'// E.g. 1.9.72 => 1,009,072
// lib version
static gradlePluginVersion = '3.5.0'
......@@ -50,15 +50,14 @@ class Config {
plugin_bintray : new DepConfig(pluginPath: "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4", pluginId: "com.jfrog.bintray"),// 上传到 bintray
plugin_traute : new DepConfig(pluginPath: "tech.harmonysoft:traute-gradle:1.1.10", pluginId: "tech.harmonysoft.oss.traute"),// 注解转非空判断
// 本地第一次上传插件新的版本需设置 isApply = false, useLocal = true
// 本地上传成功之后 isApply = true 即可应用插件来调试,后续版本更新无需设置 isApply = false
// 发布版本的话把 isApply = false, useLocal = false,更新版本号,发布成功后 isApply = true 即可使用远程库版本
plugin_api : new DepConfig(isApply: true, useLocal: false, pluginPath: "com.blankj:api-gradle-plugin:1.2", pluginId: "com.blankj.api"),
//./gradlew plugin:api-gradle-plugin:uploadArchives // 上传到本地 maven
//./gradlew plugin:api-gradle-plugin:bintrayUpload // 上传到 jcenter
// 上传新版本插件更新 pluginPath 中的版本号,并设置 isApply = false
// 通过 mavenLocal 上传本地版本,设置 isApply = true 即可应用插件来调试,最后通过 bintrayUpload 来发布插件
plugin_api : new DepConfig(isApply: true, useLocal: false, pluginPath: "com.blankj:api-gradle-plugin:1.2-r0", pluginId: "com.blankj.api"),
//./gradlew plugin:plugin_api-gradle-plugin:mavenLocal // 上传到本地 mavenLocal
//./gradlew plugin:plugin_api-gradle-plugin:bintrayUpload // 上传到 jcenter
plugin_bus : new DepConfig(isApply: true, useLocal: false, pluginPath: "com.blankj:bus-gradle-plugin:2.4", pluginId: "com.blankj.bus"),
//./gradlew plugin:bus-gradle-plugin:uploadArchives // 上传到本地 maven
//./gradlew plugin:bus-gradle-plugin:bintrayUpload // 上传到 jcenter
//./gradlew plugin:plugin_bus-gradle-plugin:mavenLocal // 上传到本地 mavenLocal
//./gradlew plugin:plugin_bus-gradle-plugin:bintrayUpload // 上传到 jcenter
support_appcompat_v7 : new DepConfig("com.android.support:appcompat-v7:$supportVersion"),
support_design : new DepConfig("com.android.support:design:$supportVersion"),
......
package com.blankj.plugin
package com.blankj.plugin.readme
import org.gradle.api.Plugin
import org.gradle.api.Project
......
package com.blankj.plugin
package com.blankj.plugin.readme
import org.gradle.api.Plugin
import org.gradle.api.Project
import static FormatUtils.LINE_SEP
class ReadmeSubPlugin implements Plugin<Project> {
@Override
......@@ -30,9 +27,9 @@ class ReadmeSubPlugin implements Plugin<Project> {
static def readmeOfSubUtil2Eng(File readmeCN, File readmeEng) {
FormatUtils.format(readmeCN)
def lines = readmeCN.readLines("UTF-8"),
sb = new StringBuilder("## How to use" + LINE_SEP
+ LINE_SEP +
"You should copy the following classes which you want to use in your project." + LINE_SEP),
sb = new StringBuilder("## How to use" + FormatUtils.LINE_SEP
+ FormatUtils.LINE_SEP +
"You should copy the following classes which you want to use in your project." + FormatUtils.LINE_SEP),
i = 3,
size = lines.size()
for (; i < size; ++i) {
......@@ -45,7 +42,7 @@ class ReadmeSubPlugin implements Plugin<Project> {
} else {
sb.append(line)
}
sb.append(LINE_SEP)
sb.append(FormatUtils.LINE_SEP)
}
readmeEng.write(sb.toString(), "UTF-8")
}
......
apply plugin: Config.depConfig.plugin_maven.pluginId
apply plugin: Config.depConfig.plugin_bintray.pluginId
/*
1. must add the following classpath in root build.gradle
classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
2. add bintrayUser, bintrayKey in root local.properties
3. apply this file in the publish module
apply from: "${rootDir.path}/gradle/publish.gradle"
publish {
name = "UtilCode"
groupId = "com.blankj"
artifactId = "utilcode"
version = "xx.xx"
website = "https://github.com/Blankj/AndroidUtilCode"
}
4. execute following command to publish
./gradlew bintrayUpload -> upload to bintray
./gradlew mavenLocal -> upload to local maven
*/
apply plugin: "com.github.dcendents.android-maven"
apply plugin: "com.jfrog.bintray"
extensions.create('publish', PublishExtension)
afterEvaluate {
def ext = project['publish'] as PublishExtension
loadBintray(ext)
configMaven(project, ext)
configBintray(project, ext)
configJavadoc(project, ext)
}
def isAndroid() {
return project.getPlugins().hasPlugin('com.android.application') ||
project.getPlugins().hasPlugin('com.android.library')
private void loadBintray(PublishExtension ext) {
Properties properties = new Properties()
File localPropertiesFile = project.rootProject.file("local.properties");
if (localPropertiesFile.exists()) {
properties.load(localPropertiesFile.newDataInputStream())
ext.bintrayUser = properties.getProperty("bintrayUser")
ext.bintrayKey = properties.getProperty("bintrayKey")
}
}
def configurePom(pom) {
def configMaven(Project project, PublishExtension ext) {
project.group = ext.groupId
project.version = ext.version
project.install {
repositories.mavenInstaller {
configPom(pom, ext)
}
}
project.tasks.create("mavenLocal", Upload) {
configuration = project.configurations.archives
repositories.mavenDeployer {
repository(url: uri(new File(project.rootDir.getPath() + "/mavenLocal")))
configPom(pom, ext)
}
doFirst {
checkExt(project, ext)
}
}
project.tasks.findByName("bintrayUpload").doFirst {
checkExt(project, ext)
}
}
def configPom(pom, PublishExtension ext) {
pom.project {
name project.ext.name
groupId = project.ext.groupId
artifactId = project.ext.artifactId
version = project.ext.versionName
name ext.name
groupId ext.groupId
artifactId ext.artifactId
version ext.version
packaging isAndroid() ? "aar" : "jar"
description project.ext.name
url project.ext.siteUrl
description ext.name
url ext.website
scm {
url project.ext.siteUrl
connection project.ext.siteUrl
developerConnection project.ext.siteUrl + ".git"
url ext.website
connection ext.website
developerConnection ext.website + ".git"
}
licenses {
......@@ -31,105 +96,128 @@ def configurePom(pom) {
developers {
developer {
id "Blankj"
name "Blankj"
id ext.bintrayUser
name ext.bintrayUser
}
}
}
}
tasks.create("mavenLocal", Upload) {
configuration = configurations.archives
repositories {
mavenDeployer {
repository(url: uri(new File(project.rootDir.getPath() + "/mavenLocal")))
configurePom(pom)
}
static def checkExt(Project project, PublishExtension ext) {
if (ext.isBintrayEmpty()) {
throw new NullPointerException("U should set bintrayUser and bintrayKey in local.properties")
}
ext.check()
}
install {
repositories.mavenInstaller {
configurePom(pom)
def configBintray(Project project, PublishExtension ext) {
project.bintray {
user = ext.bintrayUser
key = ext.bintrayKey
configurations = ['archives']
override = false
publish = true
pkg {
repo = "maven"
name = ext.name
websiteUrl = ext.website
vcsUrl = ext.website + '.git'
licenses = ["Apache-2.0"]
}
}
}
if (isAndroid()) {
// This generates sources.jar
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.source
}
private void configJavadoc(Project project, PublishExtension ext) {
if (isAndroid()) {
// This generates sources.jar
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.source
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.source
classpath += configurations.compile
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.source
classpath += configurations.compile
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
} else {
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
} else {
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
if (project.hasProperty("kotlin")) {
// Disable creating javadocs
project.tasks.withType(Javadoc) {
enabled = false
}
}
}
if (project.hasProperty("kotlin")) {
// Disable creating javadocs
tasks.withType(Javadoc) {
enabled = false
javadoc {
options {
encoding "UTF-8"
charSet 'UTF-8'
author true
version ext.version
links "http://docs.oracle.com/javase/7/docs/api"
title "${ext.name} ${ext.version}"
}
}
}
// javadoc configuration
javadoc {
options {
encoding "UTF-8"
charSet 'UTF-8'
author true
version project.ext.versionName
links "http://docs.oracle.com/javase/7/docs/api"
title "${project.ext.name} ${project.ext.versionName}"
artifacts {
archives javadocJar
archives sourcesJar
}
}
artifacts {
archives javadocJar
archives sourcesJar
def isAndroid() {
return project.getPlugins().hasPlugin('com.android.application') ||
project.getPlugins().hasPlugin('com.android.library')
}
class PublishExtension {
String name
String groupId
String artifactId
String version
String website
String bintrayUser
String bintrayKey
void check() {
checkField(name, "name")
checkField(groupId, "groupId")
checkField(artifactId, "artifactId")
checkField(version, "version")
checkField(website, "website")
checkField(bintrayUser, "bintrayUser")
checkField(bintrayKey, "bintrayKey")
}
Properties properties = new Properties()
File localPropertiesFile = project.rootProject.file("local.properties");
if (localPropertiesFile.exists()) {
properties.load(localPropertiesFile.newDataInputStream())
}
void checkField(String field, String fieldName) {
if (isEmpty(field)) {
throw new NullPointerException("$fieldName is empty!!")
}
}
boolean isBintrayEmpty() {
return isEmpty(bintrayUser) || isEmpty(bintrayKey)
}
def bintrayUser = properties.getProperty("bintrayUser")
def bintrayKey = properties.getProperty("bintrayKey")
// bintray configuration
bintray {
user = bintrayUser
key = bintrayKey
configurations = ['archives']
override = false
pkg {
repo = "maven"
name = project.ext.name
websiteUrl = project.ext.siteUrl
vcsUrl = project.ext.siteUrl + '.git'
licenses = ["Apache-2.0"]
boolean isEmpty(String str) {
return str == null || str.length() == 0
}
}
\ No newline at end of file
......@@ -39,13 +39,11 @@ dependencies {
testImplementation Config.depConfig.eventbus_lib.dep
}
ext {
apply from: "${rootDir.path}/gradle/publish.gradle"
publish {
name = "UtilCode"
groupId = Config.depConfig.lib_utilcode.groupId
artifactId = Config.depConfig.lib_utilcode.artifactId
versionName = Config.depConfig.lib_utilcode.version
siteUrl = "https://github.com/Blankj/AndroidUtilCode"
version = Config.depConfig.lib_utilcode.version
website = "https://github.com/Blankj/AndroidUtilCode"
}
apply from: "${rootDir.path}/gradle/publish.gradle"
......@@ -47,14 +47,14 @@ pluginBundle {
}
}
ext {
apply from: "${rootDir.path}/gradle/publish.gradle"
publish {
name = "ApiPlugin"
groupId = Config.depConfig.plugin_api.groupId
artifactId = Config.depConfig.plugin_api.artifactId
versionName = Config.depConfig.plugin_api.version
siteUrl = "https://github.com/Blankj/AndroidUtilCode"
version = Config.depConfig.plugin_api.version
website = "https://github.com/Blankj/AndroidUtilCode"
}
apply from: "${rootDir.path}/gradle/publish.gradle"
//./gradlew plugin:plugin_api-gradle-plugin:mavenLocal // 上传到本地 mavenLocal
//./gradlew plugin:plugin_api-gradle-plugin:bintrayUpload // 上传到 jcenter
......
......@@ -47,14 +47,14 @@ pluginBundle {
}
}
ext {
apply from: "${rootDir.path}/gradle/publish.gradle"
publish {
name = "BusPlugin"
groupId = Config.depConfig.plugin_bus.groupId
artifactId = Config.depConfig.plugin_bus.artifactId
versionName = Config.depConfig.plugin_bus.version
siteUrl = "https://github.com/Blankj/AndroidUtilCode"
version = Config.depConfig.plugin_bus.version
website = "https://github.com/Blankj/AndroidUtilCode"
}
apply from: "${rootDir.path}/gradle/publish.gradle"
//./gradlew plugin:lib_bus-gradle-plugin:mavenLocal // 上传到本地 mavenLocal
//./gradlew plugin:lib_bus-gradle-plugin:bintrayUpload // 上传到 jcenter
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册