Cannot Publish My Library

I’m publishing a library using this file for my module. However, I keep getting the stack trace below it

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.jetbrains.kotlin.android)
    id 'maven-publish'
}


android {
    namespace = "com.example.apriltaglocalization"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.apriltaglocalization"
        minSdk = 30
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

    }

    buildTypes {
        release {
//            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

publishing {
    publications {

        var groupId = project.group
        var artifactId = project.name
        version = project.version
        from components.java
    }
    repositories {
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/RithekShankar/April-Tag-Localization")
            credentials {
                username = project.findProperty("gpr.user")  ?: System.getenv("RithekShankar")
                password = project.findProperty("gpr.key") ?: System.getenv("*********")
            }

        }
    }


}

dependencies {

    implementation(libs.play.services.wearable)
    implementation(libs.roadrunner) // core
    implementation(libs.ftcVision)
    implementation(libs.ftcRobotCore)

}

Exception is:

org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.lambda$apply$1(DefaultScriptPluginFactory.java:143)
        at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:79)

And a lot more. The base one is that the components variable from components.java didn’t have a java property. What can I do to avoid this?

This is an android build, not a Java build.
Android builds have other components.
Afaik the Android Gradle Plugin even provides custom DSL for configuring the publishing.
Have a look at its documentation: Configure publication variants  |  Android Studio  |  Android Developers

Thank you! I’m intending for this to be a Java library, so how can I edit it to make it a Java build?

You apply the Android application plugin and the Kotlin Android plugin, so it is not even an Android library, but an Android application written in Kotlin.

If you want it to be a Java library, remove those plugins and apply java-library instead.

When I removed the android application plugin and the kotlin plugin from both the module and the top-level gradle files, I got this error message when building.

Please never anywhere share screenshots of text if you only want to share the text and not something additional like colors or IDE annotations. Text in images is hard to read, especially on mobile, very hard to copy, and nearly impossible to search for.

Regarding the problem, it is extremely hard to guess what you do wrong without you providing any code.
How do your build scripts look like now?
Can you also share a build --scan URL?

Sorry about that. Here is the top-level gradle file:

plugins {
//    alias(libs.plugins.android.application) apply false
//    alias(libs.plugins.jetbrains.kotlin.android) apply false
    id("java")
}

Here is the gradle file for the module:

plugins {
//    alias(libs.plugins.android.application)
//    alias(libs.plugins.jetbrains.kotlin.android)
    id 'maven-publish'
    id 'java-library'

}

//
//android {
//    namespace = "com.example.apriltaglocalization"
//    compileSdk = 34
//
//    defaultConfig {
//        applicationId = "com.example.apriltaglocalization"
//        minSdk = 30
//        targetSdk = 34
//        versionCode = 1
//        versionName = "1.0"
//
//    }
//
//    buildTypes {
//        release {
////            isMinifyEnabled = false
//            proguardFiles(
//                getDefaultProguardFile("proguard-android-optimize.txt"),
//                "proguard-rules.pro"
//            )
//        }
//    }
//    compileOptions {
//        sourceCompatibility = JavaVersion.VERSION_1_8
//        targetCompatibility = JavaVersion.VERSION_1_8
//    }
//    kotlinOptions {
//        jvmTarget = "1.8"
//    }
//}
publishing {
    publications {

        gpr(MavenPublication) {
            //from(components.java)
        }
    }
    repositories {
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/RithekShankar/April-Tag-Localization")
            credentials {
                username = project.findProperty("gpr.user")  ?: "RithekShankar"
                password = project.findProperty("gpr.key") ?: "*****"           }

        }
    }


}

dependencies {

    implementation(libs.play.services.wearable)
    implementation(libs.roadrunner) // core
    implementation(libs.ftcVision)
    implementation(libs.ftcRobotCore)

}

Here is the build scan: Build Scan® activation | Develocity

Well, yeah, look at your error message.
It says you are trying to depend on a pure-Android dependency from a Java project.
That doesn’t work out well.

The library I’m trying to publish is supposed to be run on android devices, so should I make this an android project?

I have no idea, I’m not into Android development.
But if you need to depend on other Android libraries, you probably have to make it an Android project.
But most probably not an android application project, but an android library project.