title: Maven Publish KTS - SourceSet with name 'main' not found
body: <p>I want to create a script for publish a library on kotlin.
  I am trying to convert this gradle config to gradle-kotlin (kts) following the gradle documentation (<a href="https://docs.gradle.org/current/userguide/publishing_maven.html#header" rel="nofollow noreferrer">https://docs.gradle.org/current/userguide/publishing_maven.html#header</a>) but I have this error when project builds:</p>
  <pre><code>FAILURE: Build failed with an exception.
  
  Where:
  Script '.../gradle-mvn-push.gradle.kts' line: 18 
  
  SourceSet with name 'main' not found.
  </code></pre>
  <p>Here is the script in kts:</p>
  <ul>
  <li>Kotlin version : 1.6.10</li>
  <li>Kotlin-gradle plugin version : 7.2.1</li>
  </ul>
  <pre class="lang-kotlin prettyprint-override"><code>
  apply(plugin = &quot;maven-publish&quot;)
  
  var gitLabPrivateToken: String? = null
  val secretPropertiesFile = rootProject.file(&quot;example.properties&quot;)
  if (secretPropertiesFile.exists()) {
      val secretProperties = java.util.Properties().apply {
          load(java.io.FileInputStream(secretPropertiesFile))
      }
      gitLabPrivateToken = secretProperties[&quot;token&quot;].toString()
  }
  
  val gitlabUrl = &quot;exampleUrl&quot;
  
  lateinit var sourcesArtifact: PublishArtifact
  tasks {
      val sourcesJar by creating(Jar::class) {
          archiveClassifier.set(&quot;sources&quot;)
          from(project.the&lt;SourceSetContainer&gt;()[&quot;main&quot;].allSource)
      }
  
      artifacts {
          sourcesArtifact = add(&quot;archives&quot;, sourcesJar)
      }
  }
  
  afterEvaluate {
      configure&lt;PublishingExtension&gt; {
          publications {
              create&lt;MavenPublication&gt;(&quot;maven&quot;) {
                  artifact(sourcesArtifact)  // Adds source as separate jar.
                  groupId = &quot;com.example&quot;
                  artifactId = &quot;lib&quot;
                  version = &quot;0.1.0&quot;
                  from(components[&quot;release&quot;])
              }
          }
          repositories {
              maven {
                  name = &quot;GitLabPersonal&quot;
                  url = uri(gitlabUrl)
                  credentials(HttpHeaderCredentials::class) {
                      name = &quot;Private-Token&quot;
                      value = gitLabPrivateToken
                  }
                  authentication {
                      create&lt;HttpHeaderAuthentication&gt;(&quot;header&quot;)
                  }
              }
              maven {
                  name = &quot;GitLabCi&quot;
                  url = uri(gitlabUrl)
                  credentials(HttpHeaderCredentials::class) {
                      name = &quot;Job-Token&quot;
                      value = System.getenv(&quot;CI_JOB_TOKEN&quot;)
                  }
                  authentication {
                      create&lt;HttpHeaderAuthentication&gt;(&quot;header&quot;)
                  }
              }
          }
      }
  }
  
  </code></pre>