How do I bundle javadoc/sources in Kotlin projects?

here’s what Ive tried, but I’ve reason to believe that the source jar created is probably empty, or somehow otherwise not correct. Also my javadoc apparently isn’t being generated correctly

  project.getExtensions().configure( PublishingExtension.class, ext -> {
            TaskContainer tasks = project.getTasks();
            ext.publications( pubs -> {
                TaskProvider<Jar> sources = tasks.register( "sourcesJar", Jar.class, jar -> {
                    jar.setClassifier( "sources" );
                    jar.from( project.getExtensions()
                            .getByType( SourceSetContainer.class )
                            .getByName( SourceSet.MAIN_SOURCE_SET_NAME )
                            .getAllSource()
                    );
                } );
                TaskProvider<Jar> javadocJar = tasks.register( "javadocJar", Jar.class, jar -> {
                    jar.setClassifier( "javadoc" );
                    tasks.withType( Javadoc.class, javadoc -> jar.from( javadoc.getDestinationDir() ) );
                } );
                pubs.create( "mavenJava", MavenPublication.class, pub -> {
                    MavenPom pom = pub.getPom();
                    pom.developers( devs -> {
                        devs.developer( dev -> {
                            dev.getName().set( "Caleb Cushing" );
                            dev.getEmail().set( "xenoterracide@gmail.com" );
                            dev.getUrl().set( "https://xenoterracide.com" );
                        } );
                    } );
                    pub.from( project.getComponents().getAt( "java" ) );
                    pub.artifact( sources.get() );
                    pub.artifact( javadocJar.get() );
                } );
            } );
        });
  > Could not create task ':javadocJar'.
      > DefaultTaskContainer#withType(Class, Action) on task set cannot be executed in the current context

https://bitbucket.org/xenoterracide/gradle-bundle-kotlin-lib/src/master/src/main/java/com/xenoterracide/gradle/bundle/kotlin/KotlinLibraryProjectDefaultsPlugin.java

how can I fix this code so that javadoc and the java/kotlin sources in my project are bundled correctly and in a way that intellij will recognize