Skip to content

Commit

Permalink
Add way to publish to MavenLocal (#11)
Browse files Browse the repository at this point in the history
* Add way to publish to MavenLocal

* Update update_version.sh
  • Loading branch information
ruixhuang authored Oct 31, 2023
1 parent cc00fac commit 2b31686
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 51 deletions.
10 changes: 8 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name="exchange.dydx.carteraexample.CarteraSampleApplication"
android:name=".CarteraSampleApplication"
android:allowBackup="true"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
Expand All @@ -14,9 +14,15 @@
tools:targetApi="31" >

<activity
android:name="exchange.dydx.carteraexample.MainActivity"
android:name=".MainActivity"
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'com.android.application' version '8.1.1' apply false
id 'com.android.library' version '8.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
id 'com.google.dagger.hilt.android' version '2.41' apply false
}
45 changes: 6 additions & 39 deletions cartera/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'maven-publish'
}

android {
Expand Down Expand Up @@ -77,47 +78,13 @@ dependencies {
}

apply plugin: 'maven-publish'

task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier.set("sources")
}

publishing {
publications {
maven(MavenPublication) {
groupId "dydxprotocol"
artifactId "cartera-android"
version "0.0.6"
artifact sourceJar
artifact "$buildDir/outputs/aar/cartera-release.aar"

pom {
withXml {
def dependenciesNode = asNode().appendNode('dependencies')

project.configurations.implementation.allDependencies.each {
if (it.group != null || it.name != null || it.version != null || it.name == "unspecified") return

def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}

repositories {
maven {
def github_username = System.getenv('github_username')
def github_token = System.getenv('github_token')
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/dydxprotocol/cartera-android")
credentials {
username github_username
password github_token
}
}
}
}
// !!!! Switch between local and remote publishing here: !!!!
// IMPORTANT: Be sure to switch back to "publishRemote" before committing. Otherwise, the deployment will fail.
//apply from: 'publishLocal.gradle'
apply from: 'publishRemote.gradle'
52 changes: 52 additions & 0 deletions cartera/publishLocal.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

project.afterEvaluate {
publishToMavenLocal {
def groupId = LIBRARY_GROUP
def artifactId = LIBRARY_ARTIFACT_ID
def versionName = LIBRARY_VERSION_NAME + "-local"
def debugSuffix = "-debug"
def releaseSuffix = "-release"
publishing {
publications {
LibraryRelease(MavenPublication) {
from components.release
// artifact(sourceJar)
setGroupId groupId
setArtifactId artifactId
version versionName + releaseSuffix
}
LibraryDebug(MavenPublication) {
from components.debug
// artifact(sourceJar)
setGroupId groupId
setArtifactId artifactId
version versionName + debugSuffix
}
}
publications.all {
pom.withXml {
asNode().dependencies.'*'
.findAll() {
it.scope.text() == 'runtime' &&
project.configurations.implementation.allDependencies.find {
dep -> dep.name == it.artifactId.text()
}
}.each { it.scope*.value = 'compile'}
}
}
}

doLast {
def prettyPrint = {
1.upto(100, { print "=" })
println()
}
println()
prettyPrint()
println "PUBLICATION FINISHED"
println "Artifact RELEASE: " + groupId + ":" + artifactId + ":" + versionName + releaseSuffix
println "Artifact DEBUG: " + groupId + ":" + artifactId + ":" + versionName + debugSuffix
prettyPrint()
}
}
}
39 changes: 39 additions & 0 deletions cartera/publishRemote.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
publishing {
publications {
maven(MavenPublication) {
groupId LIBRARY_GROUP
artifactId LIBRARY_ARTIFACT_ID
version LIBRARY_VERSION_NAME
artifact sourceJar
artifact "$buildDir/outputs/aar/cartera-release.aar"

pom {
withXml {
def dependenciesNode = asNode().appendNode('dependencies')

project.configurations.implementation.allDependencies.each {
if (it.group != null || it.name != null || it.version != null || it.name == "unspecified") return

def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}

repositories {
maven {
def github_username = System.getenv('github_username')
def github_token = System.getenv('github_token')
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/dydxprotocol/cartera-android")
credentials {
username github_username
password github_token
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ data class Wallet (
@SerializedName("mobile" ) var mobile : WalletMobile? = WalletMobile(),
@SerializedName("desktop" ) var desktop : WalletDesktop? = WalletDesktop(),
@SerializedName("metadata" ) var metadata : WalletMetadata? = WalletMetadata(),
@SerializedName("config" ) var config : WalletConfig? = WalletConfig()
@SerializedName("config" ) var config : WalletConfig? = WalletConfig(),
@SerializedName("userFields" ) var userFields : Map<String, String>? = null
)

data class WalletApp (
Expand Down
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true

LIBRARY_GROUP=dydxprotocol
LIBRARY_ARTIFACT_ID=cartera-android
LIBRARY_VERSION_NAME=0.0.7
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pluginManagement {
repositories {
google()
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
Expand All @@ -9,6 +10,7 @@ dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenLocal()
mavenCentral()
maven { url "https://repo1.maven.org/maven2/" }
maven {
Expand Down
10 changes: 4 additions & 6 deletions update_version.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/bin/sh

# search for the first line that starts with "version" in cartera/ build.gradle
# get the value in the quotes
VERSION=$(grep "^ version" cartera/build.gradle | sed -n 's/ version "\(.*\)"/\1/p')

# find the version number from the line LIBRARY_VERSION_NAME=0.0.1 in gradle.properties
# and assign it to the variable VERSION
VERSION=$(grep "^LIBRARY_VERSION_NAME=" gradle.properties | sed -n 's/LIBRARY_VERSION_NAME=\(.*\)/\1/p')

echo "Current version is $VERSION. Enter new version (or press enter to skip):"
read NEW_VERSION

#if NEW_VERSION is not empty, replace the version in build.gradle
if [ ! -z "$NEW_VERSION" ]; then
echo "Updating version to $NEW_VERSION"
sed -i '' "s/version \"$VERSION\"/version \"$NEW_VERSION\"/" cartera/build.gradle
sed -i '' "s/LIBRARY_VERSION_NAME=$VERSION/LIBRARY_VERSION_NAME=$NEW_VERSION/" gradle.properties
fi

0 comments on commit 2b31686

Please sign in to comment.