Skip to content

Commit

Permalink
Fix package and publish to MavenCentral
Browse files Browse the repository at this point in the history
  • Loading branch information
wada811 committed Dec 29, 2022
1 parent 5653b59 commit 119f814
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 84 deletions.
6 changes: 6 additions & 0 deletions .envrc.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export OSSRH_USERNAME=
export OSSRH_PASSWORD=
export SONATYPE_STAGING_PROFILE_ID=
export SIGNING_KEY_ID=
export SIGNING_PASSWORD=
export SIGNING_KEY=
28 changes: 28 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish to MavenCentral

on:
release:
types: [ released ]

jobs:
publish:
name: Publish to MavenCentral
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 11

- name: Publish to MavenCentral
run: ./gradlew --max-workers 1 publishReleasePublicationToMavenLocal publishReleasePublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,6 @@ Network Trash Folder
Temporary Items
.apdisk

# End of https://www.gitignore.io/api/macos,android,intellij+iml,androidstudio
# End of https://www.gitignore.io/api/macos,android,intellij+iml,androidstudio

.envrc
2 changes: 0 additions & 2 deletions .jitpack.yml

This file was deleted.

24 changes: 6 additions & 18 deletions DataBinding-ktx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ plugins {
id 'maven-publish'
}

apply from: "${rootDir}/publish-module.gradle"

android {
namespace "com.wada811.databinding"
compileSdkVersion 32
namespace "com.wada811.databindingktx"
compileSdkVersion 33
defaultConfig {
minSdkVersion 16
targetSdkVersion 32
minSdkVersion 21
targetSdkVersion 33
}
buildFeatures {
dataBinding true
Expand All @@ -27,19 +29,5 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0"
//noinspection GradleDependency
implementation 'androidx.fragment:fragment-ktx:1.5.5'
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
groupId = "com.github.wada811"
artifactId = "DataBinding-ktx"
version = "7.0.0"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,14 @@

package com.wada811.databinding

import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.FragmentActivity
import com.wada811.databindingktx.dataBinding
import com.wada811.databindingktx.withBinding

@Deprecated("Use withBinding", level = DeprecationLevel.WARNING)
fun <T : ViewDataBinding> FragmentActivity.dataBinding(): Lazy<T> = lazy(LazyThreadSafetyMode.NONE) {
bind<T>(getContentView()).also {
it.lifecycleOwner = this@dataBinding
}
}
@Deprecated("Import com.wada811.databindingktx", ReplaceWith("dataBinding()", "com.wada811.databindingktx.dataBinding"))
fun <T : ViewDataBinding> FragmentActivity.dataBinding(): Lazy<T> = this.dataBinding()

fun <T : ViewDataBinding> FragmentActivity.withBinding(withBinding: (binding: T) -> Unit) {
val binding = bind<T>(getContentView()).also {
it.lifecycleOwner = this@withBinding
}
withBinding(binding)
}
@Deprecated("Import com.wada811.databindingktx", ReplaceWith("withBinding<T>(bind)", "com.wada811.databindingktx.withBinding"))
fun <T : ViewDataBinding> FragmentActivity.withBinding(bind: (binding: T) -> Unit) = this.withBinding(bind)

private fun <T : ViewDataBinding> bind(view: View): T = DataBindingUtil.bind(view)!!
private fun FragmentActivity.getContentView(): View {
return checkNotNull(findViewById<ViewGroup>(android.R.id.content).getChildAt(0)) {
"Call setContentView or Use Activity's secondary constructor passing layout res id."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,15 @@

package com.wada811.databinding

import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.wada811.databindingktx.dataBinding
import com.wada811.databindingktx.withBinding
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty

@Deprecated("Use withBinding", level = DeprecationLevel.WARNING)
fun <T : ViewDataBinding> Fragment.dataBinding(): ReadOnlyProperty<Fragment, T> {
return object : ReadOnlyProperty<Fragment, T> {
@Suppress("UNCHECKED_CAST")
override fun getValue(thisRef: Fragment, property: KProperty<*>): T {
(requireView().getTag(R.id.data_binding_tag) as? T)?.let { return it }
return bind<T>(requireView()).also {
it.lifecycleOwner = thisRef.viewLifecycleOwner
it.root.setTag(R.id.data_binding_tag, it)
}
}
@Deprecated("Import com.wada811.databindingktx", ReplaceWith("dataBinding()", "com.wada811.databindingktx.dataBinding"))
fun <T : ViewDataBinding> Fragment.dataBinding(): ReadOnlyProperty<Fragment, T> = this.dataBinding()

private fun <T : ViewDataBinding> bind(view: View): T = DataBindingUtil.bind(view)!!
}
}

fun <T : ViewDataBinding> Fragment.withBinding(withBinding: (binding: T) -> Unit) {
view?.let { view ->
val binding = DataBindingUtil.bind<T>(view)!!.also {
it.lifecycleOwner = viewLifecycleOwner
}
withBinding(binding)
}
}
@Deprecated("Import com.wada811.databindingktx", ReplaceWith("withBinding<T>(bind)", "com.wada811.databindingktx.withBinding"))
fun <T : ViewDataBinding> Fragment.withBinding(bind: (binding: T) -> Unit) = this.withBinding(bind)

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@file:JvmName("ActivityDataBinding")

package com.wada811.databindingktx

import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.FragmentActivity

fun <T : ViewDataBinding> FragmentActivity.dataBinding(): Lazy<T> = lazy(LazyThreadSafetyMode.NONE) {
bind<T>(getContentView()).also {
it.lifecycleOwner = this@dataBinding
}
}

fun <T : ViewDataBinding> FragmentActivity.withBinding(withBinding: (binding: T) -> Unit) {
val binding = bind<T>(getContentView()).also {
it.lifecycleOwner = this@withBinding
}
withBinding(binding)
}

private fun <T : ViewDataBinding> bind(view: View): T = DataBindingUtil.bind(view)!!
private fun FragmentActivity.getContentView(): View {
return checkNotNull(findViewById<ViewGroup>(android.R.id.content).getChildAt(0)) {
"Call setContentView or Use Activity's secondary constructor passing layout res id."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@file:JvmName("FragmentDataBinding")

package com.wada811.databindingktx

import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.wada811.databindingktx.R
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty

fun <T : ViewDataBinding> Fragment.dataBinding(): ReadOnlyProperty<Fragment, T> {
return object : ReadOnlyProperty<Fragment, T> {
@Suppress("UNCHECKED_CAST")
override fun getValue(thisRef: Fragment, property: KProperty<*>): T {
(requireView().getTag(R.id.data_binding_tag) as? T)?.let { return it }
return bind<T>(requireView()).also {
it.lifecycleOwner = thisRef.viewLifecycleOwner
it.root.setTag(R.id.data_binding_tag, it)
}
}

private fun <T : ViewDataBinding> bind(view: View): T = DataBindingUtil.bind(view)!!
}
}

fun <T : ViewDataBinding> Fragment.withBinding(withBinding: (binding: T) -> Unit) {
view?.let { view ->
val binding = DataBindingUtil.bind<T>(view)!!.also {
it.lifecycleOwner = viewLifecycleOwner
}
withBinding(binding)
}
}

26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ withBinding<DataBindingActivityBinding> { binding ->
}
```

### [Deprecated] Delegated Property
### Delegated Property

```kotlin
private val binding: DataBindingActivityBinding by dataBinding()
Expand All @@ -33,7 +33,7 @@ If you access the binding property when fragment's view may be destroyed, you mu

## Gradle

[![](https://jitpack.io/v/wada811/DataBinding-ktx.svg)](https://jitpack.io/#wada811/DataBinding-ktx)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.wada811.databindingktx/databindingktx/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.wada811.databindingktx/databindingktx)

```groovy
android {
Expand All @@ -43,14 +43,32 @@ android {
}
repositories {
maven { url "https://www.jitpack.io" }
mavenCentral()
}
dependencies {
implementation 'com.github.wada811:DataBinding-ktx:x.y.z'
implementation 'com.wada811.databindingktx:databindingktx:x.y.z'
}
```

## Migrations

### 7.0.0

#### dependencies

```diff
- implementation 'com.github.wada811:DataBinding-ktx:x.y.z'
+ implementation 'com.wada811.databindingktx:databindingktx:x.y.z'
```

#### package

```diff
-import com.wada811.databinding
+import com.wada811.databindingktx
```

## License

Copyright (C) 2020 wada811
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ plugins {
id 'com.android.library' version '7.3.1' apply false
id "com.diffplug.spotless" version "6.12.0" apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
}

apply from: "${rootDir}/publish-root.gradle"
72 changes: 72 additions & 0 deletions publish-module.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

ext {
PUBLISH_GROUP_ID = 'com.wada811.databindingktx'
PUBLISH_ARTIFACT_ID = 'databindingktx'
PUBLISH_VERSION = '7.0.0'
}

android {
publishing {
singleVariant('release') {
withSourcesJar()
}
}
}

signing {
useInMemoryPgpKeys(
rootProject.ext["signing.keyId"],
rootProject.ext["signing.key"],
rootProject.ext["signing.password"],
)
sign publishing.publications
}

group = PUBLISH_GROUP_ID
version = PUBLISH_VERSION

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION

// Two artifacts, the `aar` (or `jar`) and the sources
if (project.plugins.findPlugin("com.android.library")) {
from components.release
} else {
from components.java
}

pom {
name = PUBLISH_ARTIFACT_ID
description = 'DataBinding-ktx make easy to use DataBinding.'
url = 'https://github.com/wada811/DataBinding-ktx'

licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'wada811'
name = 'WADA Takumi'
email = '[email protected]'
}
}
scm {
connection = 'scm:git:github.com/wada811/DataBinding-ktx.git'
developerConnection = 'scm:git:ssh://github.com/wada811/DataBinding-ktx.git'
url = 'https://github.com/wada811/DataBinding-ktx/tree/master'
}
}
}
}
}
}
18 changes: 18 additions & 0 deletions publish-root.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.key"] = System.getenv('SIGNING_KEY')

nexusPublishing {
repositories {
sonatype {
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
Loading

0 comments on commit 119f814

Please sign in to comment.