Adding classifier = "proguard"
solved it, although I'm not familar with proguard to determine if the publication is correct.
artifacts {
proguard(new File(proguard.outJarFiles[0])) {
builtBy(proguard)
classifier = "proguard"
}
}
Here's what was published for me:

I can see that the original JAR is 592 bytes while the proguard one is 410 bytes, so I am assuming it worked correctly.
Also while debugging your issue, I refactored to use the Kotlin DSL which I recommend using.
import proguard.gradle.ProGuardTask
plugins {
`java-library`
`maven-publish`
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("net.sf.proguard:proguard-gradle:6.2.2")
}
}
group = "org.example"
version = "1.0.0"
repositories {
jcenter()
}
configurations {
val implementation by this
val runtimeOnly by this
create("proguard") {
isCanBeConsumed = false
isCanBeResolved = false
extendsFrom(implementation, runtimeOnly)
attributes {
attribute(Attribute.of("org.gradle.usage", String::class.java), Usage.JAVA_API)
attribute(Attribute.of("org.gradle.category", String::class.java), Category.LIBRARY)
attribute(Attribute.of("org.gradle.libraryelements", String::class.java), LibraryElements.JAR)
attribute(Attribute.of("org.gradle.dependency.bundling", String::class.java), Bundling.EXTERNAL)
}
}
}
dependencies {
api("org.apache.commons:commons-math3:3.6.1")
implementation("com.google.guava:guava:23.0")
testImplementation("junit:junit:4.12")
}
val proguard by tasks.registering(ProGuardTask::class) {
description = "Optimizes and obfuscates the created distribution jar."
dependsOn(tasks.named("jar"))
verbose()
injars("$buildDir/libs/${project.name}-${project.version}.jar")
outjars("$buildDir/proguard/${project.name}-${version}.jar")
if (System.getProperty("java.version").startsWith("1.")) {
libraryjars("${System.getProperty("java.home")}/lib/rt.jar")
} else {
libraryjars(mapOf("jarfilter" to "!**.jar", "filter" to "!module-info.class"), "${System.getProperty("java.home")}/jmods/java.base.jmod")
}
libraryjars(configurations.named("runtimeClasspath").get().files)
printmapping("out.map")
keep("""
public class * {
public protected *;
}
""".trimIndent())
keepclassmembers(mapOf("allowoptimization" to true), """
enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
""".trimIndent())
keepclassmembers("""
class * implements java.io.Serializable {
static final long serialVersionUID;
static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace ();
java.lang.Object readResolve ();
}
""".trimIndent())
overloadaggressively()
}
val javaComponent = project.components.findByName("java") as AdhocComponentWithVariants
javaComponent.addVariantsFromConfiguration(configurations.getByName("proguard")) {
// I have no idea what I should do here and the documentation is very confusing
}
publishing {
publications {
create<MavenPublication>("myLibrary") {
from(components["java"])
artifact(proguard.get().outJarFiles[0]) {
builtBy(proguard.get())
classifier = "proguard"
}
}
}
repositories {
maven {
name = "myRepo"
url = uri("file://${buildDir}/repo")
}
}
}
tasks.named("publish").configure {
dependsOn(tasks.named("proguard"))
}