Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ val Project.downloadVersion: String
return if (CI.isCiBuild || isFDroidBuild) {
publishingVersion
} else {
// sometimes, when working locally, Gradle fails to download the latest snapshot version
// this may cause issues while initializing the project in AndroidIDE
VersionUtils.getLatestSnapshotVersion("gradle-plugin")
VersionUtils.LATEST_INTEGRATION
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@

package com.itsaky.androidide.build.config

import org.gradle.api.GradleException
import java.io.BufferedInputStream
import java.net.URI
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.xpath.XPathFactory

/**
* @author Akash Yadav
*/
Expand All @@ -41,44 +35,4 @@ object VersionUtils {
* The latest integration version name.
*/
const val LATEST_INTEGRATION = "latest.integration"

/**
* The cached version name.
*/
private var cachedVersion: String? = null

/**
* Gets the latest snapshot version of the given artifact from the Sonatype snapshots repository.
*/
@JvmStatic
fun getLatestSnapshotVersion(artifact: String): String {
cachedVersion?.also { cached ->
println("Found latest version of artifact '$artifact' : '$cached' (cached)")
return cached
}

val groupId = BuildConfig.PACKAGE_NAME.replace('.', '/')
val moduleMetadata = "$SONATYPE_SNAPSHOTS_REPO$groupId/$artifact/maven-metadata.xml"
return try {
BufferedInputStream(URI.create(moduleMetadata).toURL().openStream()).use { inputStream ->
val builderFactory = DocumentBuilderFactory.newInstance()
val builder = builderFactory.newDocumentBuilder()
val document = builder.parse(inputStream)

val xPathFactory = XPathFactory.newInstance()
val xPath = xPathFactory.newXPath()

val latestVersion = xPath.evaluate("/metadata/versioning/latest", document)
cachedVersion = latestVersion
println("Found latest version of artifact '$artifact' : '$latestVersion'")
return@use latestVersion
}
} catch (err: Throwable) {
if (CI.isCiBuild) {
throw GradleException("Failed to download: $moduleMetadata", err)
}
println("Failed to download $moduleMetadata: ${err.message}")
return LATEST_INTEGRATION
}
}
}
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") }
maven { url = uri("https://s01.oss.sonatype.org/content/groups/public/") }
maven { url = uri("https://jitpack.io") }
}
}
Expand Down
Loading