title: How to refactor uploadArchives for some subprojects at root build.gradle?
body: <p>I have a multi project, and I want to upload some of the subprojects artifact to the maven repository.
  For now, I wrote the following code into the main build.gradle:</p>
  
  <pre><code>task sourcesJar(type: Jar, dependsOn: classes) { ... }
  
  project(':subProjName1') {
     apply plugin: 'java'
     apply plugin: 'maven'
  
     configurations {
         subProjName1Archives
     }
  
     uploadSubProjName1Archives {
         repositories {
             mavenDeployer {
                 repository(url: "file:///$rootDir/mvn-repo/")
             }
         }
     }
  
     artifacts {
         subProjName1Archives jar
         subProjName1Archives sourcesJar
     }
  }
  
  project(':subProjName2') { ... }
  ...
  project(':subProjNameN') { ... }
  </code></pre>
  
  <p>And do following for upload archives:</p>
  
  <pre><code>gradlew.bat uploadSubProjName1Archives
  gradlew.bat uploadSubProjName2Archives
  ...
  gradlew.bat uploadSubProjNameNArchives
  </code></pre>
  
  <p>It's doing what I want, but how can I generalize it into one task in the main build.gradle?</p>