@@ -567,6 +567,7 @@ class BuildPlugin implements Plugin<Project>  {
567567
568568    private  void  configureMaven (Project  project ) {
569569        project. getPluginManager(). apply(" maven-publish"  )
570+         project. getPluginManager(). apply(" com.gradleup.nmcp"  )
570571
571572        //  Configure Maven publication
572573        project. publishing {
@@ -587,13 +588,6 @@ class BuildPlugin implements Plugin<Project>  {
587588        //  Configure Maven Pom
588589        configurePom(project, project. publishing. publications. main)
589590
590-         //  Disable the publishing tasks since we only need the pom generation tasks.
591-         //  If we are working with a project that has a scala variant (see below), we need to modify the pom's
592-         //  artifact id which the publish task does not like (it fails validation when run).
593-         project. getTasks(). withType(PublishToMavenRepository ) { PublishToMavenRepository  m  -> 
594-             m. enabled =  false 
595-         }
596- 
597591        //  Configure Scala Variants if present
598592        project. getPlugins(). withType(SparkVariantPlugin ). whenPluginAdded {
599593            //  Publishing gets weird when you introduce variants into the project.
@@ -608,7 +602,8 @@ class BuildPlugin implements Plugin<Project>  {
608602
609603            //  Main variant needs the least configuration on its own, since it is the default publication created above.
610604            sparkVariants. defaultVariant { SparkVariant  variant  -> 
611-                 updateVariantPomLocationAndArtifactId(project, project. publishing. publications. main, variant)
605+                 project. publishing. publications. main. setAlias(true )
606+                 updateVariantArtifactId(project, project. publishing. publications. main, variant)
612607            }
613608
614609            //  For each spark variant added, we need to do a few things:
@@ -659,7 +654,7 @@ class BuildPlugin implements Plugin<Project>  {
659654                            suppressAllPomMetadataWarnings() //  We get it. Gradle metadata is better than Maven Poms
660655                        }
661656                        configurePom(project, variantPublication)
662-                         updateVariantPomLocationAndArtifactId (project, variantPublication, variant)
657+                         updateVariantArtifactId (project, variantPublication, variant)
663658                    }
664659                }
665660            }
@@ -672,14 +667,6 @@ class BuildPlugin implements Plugin<Project>  {
672667    }
673668
674669    private  static  void  configurePom (Project  project , MavenPublication  publication ) {
675-         //  Set the pom's destination to the distribution directory
676-         project. tasks. withType(GenerateMavenPom ). all { GenerateMavenPom  pom  -> 
677-             if  (pom. name ==  " generatePomFileFor${ publication.name.capitalize()}  Publication"  ) {
678-                 BasePluginExtension  baseExtension =  project. getExtensions(). getByType(BasePluginExtension . class);
679-                 pom. destination =  project. provider({" ${ project.buildDir}  /distributions/${ baseExtension.archivesName.get()}  -${ project.getVersion()}  .pom"  })
680-             }
681-         }
682- 
683670        //  add all items necessary for publication
684671        Provider<String >  descriptionProvider =  project. provider({ project. getDescription() })
685672        MavenPom  pom =  publication. getPom()
@@ -722,7 +709,8 @@ class BuildPlugin implements Plugin<Project>  {
722709                    while  (dependenciesIterator. hasNext()) {
723710                        Node  dependencyNode =  dependenciesIterator. next()
724711                        String  artifact =  dependencyNode. get(" artifactId"  ). text()
725-                         if  (artifact ==  dependency. getName()) {
712+                         //  handle scala variants by splitting via "_" and checking the first part
713+                         if  (artifact =~  dependency. getName(). split(' _'  )[0 ]) {
726714                            dependenciesIterator. remove()
727715                            break 
728716                        }
@@ -732,23 +720,11 @@ class BuildPlugin implements Plugin<Project>  {
732720        }
733721    }
734722
735-     private  static  void  updateVariantPomLocationAndArtifactId (Project  project , MavenPublication  publication , SparkVariant  variant ) {
723+     private  static  void  updateVariantArtifactId (Project  project , MavenPublication  publication , SparkVariant  variant ) {
736724        //  Add variant classifier to the pom file name if required
737-         String  classifier =  variant. shouldClassifySparkVersion() &&  variant. isDefaultVariant() ==  false  ?  " -${ variant.getName()} "   :  ' ' 
738725        BasePluginExtension  baseExtension =  project. getExtensions(). getByType(BasePluginExtension . class);
739-         String  filename =  " ${ baseExtension.archivesName.get()}  _${ variant.scalaMajorVersion}  -${ project.getVersion()}${ classifier} " 
740-         //  Fix the pom name
741-         project. tasks. withType(GenerateMavenPom ). all { GenerateMavenPom  pom  -> 
742-             if  (pom. name ==  " generatePomFileFor${ publication.name.capitalize()}  Publication"  ) {
743-                 pom. destination =  project. provider({" ${ project.buildDir}  /distributions/${ filename}  .pom"  })
744-             }
745-         }
746-         //  Fix the artifactId. Note: The publishing task does not like this happening. Hence it is disabled.
747-         publication. getPom(). withXml { XmlProvider  xml  -> 
748-             Node  root =  xml. asNode()
749-             Node  artifactId =  (root. get(' artifactId'  ) as  NodeList ). get(0 ) as  Node 
750-             artifactId. setValue(" ${ baseExtension.archivesName.get()}  _${ variant.scalaMajorVersion} "  )
751-         }
726+         //  Fix the artifact id
727+         publication. setArtifactId(" ${ baseExtension.archivesName.get()}  _${ variant.scalaMajorVersion} "  )
752728    }
753729
754730    /** 
0 commit comments