SSLContext getDefault - NoSuchAlgorithmException

I have a build script that I use to publish my version catalog to my nexus maven repository. Here’s the build script:

buildscript {
    dependencies {
        classpath("com.android.tools.build:gradle:7.2.0")
    }

}
plugins {
    id ("version-catalog")
    id ("maven-publish")
}
catalog {
    versionCatalog {
        from(files("gradle/libs.versions.toml"))
    }
}

publishing {
    publications {
        create<MavenPublication>("VersionCatalog") {
            groupId = "com.phinneyridge"
            artifactId = "com.phinneyridge.version.catalog"
            version = "1.0.0"
            from(components["versionCatalog"])
        }
        repositories {
            maven {
                name = "PhinneyRidgeRepository"
                url = uri(System.getenv()["PhinneyRidgeReleaseRepoUrl"].toString())
                credentials {
                    username = System.getenv().get("PhinneyRidgeRepoUser").toString()
                    password = System.getenv().get("PhinneyRidgeRepoUserPW").toString()
                }
                println(url)
                println(credentials.username + ":" + credentials.password)
            }
        }
    }
}

When I try to publish the version catalog, I get an SSL related error “NoSuchAlgorithm”. If I use “mavenLocal()” instead of my declared maven repository, it successfully publishes the version catalog to the local maven repository.

To solve the problem, I had to add a line to the maven repository declaration. Here’s the change:

            maven {
                name = "PhinneyRidgeRepository"
                javax.net.ssl.SSLContext.setDefault(javax.net.ssl.SSLContext.getInstance("Default"))
                url = uri(System.getenv()["PhinneyRidgeReleaseRepoUrl"].toString())
                credentials {
                    username = System.getenv().get("PhinneyRidgeRepoUser").toString()
                    password = System.getenv().get("PhinneyRidgeRepoUserPW").toString()
                }
                println(url)
                println(credentials.username + ":" + credentials.password)
            }

That additional line of code solved the problem I was able to successfully publish the version catalog to my nexus maven repository.

What’s particularly interesting is that I have another build script that publishes a custom gradle plugin to the same nexus maven repository. The repository is declared in the same manner as I first described without the need for setting the default SSLContext and it works perfectly fine. I believe that this is a gradle bug that the SSLContext does not get initialized perhaps due to the fact that the publication is coming from a component as that is the only obvious difference I see between the build script that works and the build script that doesn’t work without the SSLContext getting declaratively initialized. Perhaps there’s another explanation, but it’s certainly not intuitive that the SSLContext needs to be physical initialized in some situations.

For additional information you can see: StackOverflow posting

If that is a bug, you should open a bug report on GitHub instead of a post here. :slight_smile:
But the difference you see is a red herring I think.
In the plugin project the com.gradle.plugin-publish plugin sets up the publication and should also publish from a component.
But I guess without more information or you debugging further, Gradle guys will not be able to reproduce or fix the issue.