Skip to content

Instantly share code, notes, and snippets.

View gmazzo's full-sized avatar

Guillermo Mazzola gmazzo

  • Glovo
  • Barcelona
  • 05:40 (UTC +01:00)
  • Instagram gmazzo65
View GitHub Profile
@gmazzo
gmazzo / ChecksumTask.kt
Last active August 29, 2022 15:47
A Gradle task to compute checksums
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import java.security.MessageDigest
@CacheableTask
abstract class Checksum : DefaultTask() {
@gmazzo
gmazzo / DownloadFileTask.kt
Last active August 29, 2022 15:48
The missing "download to file" task for Gradle
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.gradle.workers.WorkAction
import org.gradle.workers.WorkParameters
import org.gradle.workers.WorkerExecutor
import java.net.HttpURLConnection
import java.net.URL
@gmazzo
gmazzo / android-publish.gradle.kts
Last active October 15, 2021 12:35
Android Library Variant-Aware Publication (with sources)
import org.gradle.api.attributes.LibraryElements
import org.gradle.api.component.ConfigurationVariantDetails
import org.gradle.api.plugins.JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME
import org.gradle.jvm.tasks.Jar
import java.util.Locale
plugins {
id("com.android.library")
`maven-publish`
}
@gmazzo
gmazzo / build.gradle.kts
Created September 7, 2021 10:25
Android Library Maven Publication (with sources)
plugins {
id("com.android.library")
`maven-publish`
}
publishing {
repositories {
// TODO define your publish repos here
}
publications {
@gmazzo
gmazzo / build.gradle.kts
Created September 7, 2021 09:58
Android Library Maven Publication
plugins {
id("com.android.library")
`maven-publish`
}
publishing {
repositories {
// TODO define your publish repos here
}
publications {
@gmazzo
gmazzo / NativeCollections.kt
Last active November 26, 2022 18:41
A Kotlin/Native thread-safe `List`, `Set` and `Map` implementations
package kotlin.native.concurrent
fun <T> AtomicReference<T>.computeAndSet(transform: T.() -> T) = with(value) {
@Suppress("ControlFlowWithEmptyBody")
while (!compareAndSet(this, transform().freeze()));
this
}
@gmazzo
gmazzo / CompletableSemaphore.kt
Last active March 6, 2020 08:47
A `Completable` class implementing a `Semaphore` behavior
import io.reactivex.Completable
import io.reactivex.Completable.defer
import io.reactivex.CompletableObserver
import java.util.concurrent.atomic.AtomicReference
class CompletableSemaphore(
private val hasPermission: () -> Boolean,
private val acquirePermission: Completable
) : Completable() {
private val complete = complete()
@gmazzo
gmazzo / jacoco.gradle
Created December 16, 2018 17:09
Jacoco script for Android unit and instrumentation tests coverage report, supporting Kotlin
apply plugin: 'jacoco'
jacoco {
toolVersion = '0.8.2'
}
android {
buildTypes {
debug {
@gmazzo
gmazzo / wsdl2java.gradle
Last active June 29, 2018 02:05
WSDL SOAP JAX-WB client generation with Gradle
import org.gradle.process.internal.ExecActionFactory
import org.gradle.process.internal.JavaExecAction
import javax.inject.Inject
configurations {
jaxws
}
dependencies.add('jaxws', 'com.sun.xml.ws:jaxws-tools:2.2.10')
@gmazzo
gmazzo / integrationTests.gradle
Created April 3, 2018 13:31
Integration tests sourceSet script for a Gradle Java project
sourceSets {
integrationTest {
compileClasspath += sourceSets.main.output + configurations.testRuntime
runtimeClasspath += output + compileClasspath
}
}
configurations {
integrationTestCompile {
extendsFrom configurations.testCompile