No components found when creating a new publication within a custom plugin

I’m creating a custom plugin to standardise our Maven publishing configuration across all our internal projects. When this plugin is applied to an Android library project there are no components available. However, if I add the same configuration directly to the build.gradle file there are components available.

I suspect there is a gap in my knowledge of when the components are created by the Android library plugin. Any help would be greatly appreciated. Here is an example of what my plugin is doing and the debug output has no components:

class MyPublishPlugin : Plugin<Project> {
    override fun apply(project: Project) {
        project.plugins.apply("maven-publish")

        project.afterEvaluate { _ ->
            project.extensions.configure(PublishingExtension::class.java) { publishing ->
                publishing.publications.create("release", MavenPublication::class.java) { _ ->
                    project.logger.debug("Available components: {}", project.components.names)
                }
            }
        }
    }
}

And here is what I have added to build.gradle which does have components listed in the debug output:

afterEvaluate {
  publishing {
    publications {
      release(MavenPublication) {
        println 'Components ' + components.names
      }
    }
  }
}

Here is the full build.gradle file:

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'maven-publish'
}

android {
    compileSdkVersion 30

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0.3"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        debug {
            testCoverageEnabled = true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
        xmlReport true
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.30"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'

    implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
    implementation 'io.reactivex.rxjava3:rxjava:3.0.0'

    implementation "com.squareup.retrofit2:retrofit:2.9.0"
    implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'
    implementation "com.squareup.retrofit2:converter-gson:2.9.0"
    implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

afterEvaluate {
  publishing {
    publications {
      release(MavenPublication) {
        println 'Components ' + components.names
      }
    }
  }
}