All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.darylteo.gradle.plugins.MavenPlugin.groovy Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
/*
 * Copyright 2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.darylteo.gradle.plugins

import org.gradle.api.*
import org.gradle.api.artifacts.maven.*
import org.gradle.api.logging.*
import org.gradle.api.tasks.bundling.*

import com.darylteo.gradle.vertx.tasks.*

public class MavenPlugin implements org.gradle.api.Plugin {
  void apply(Project project) {
    project.with {
      // apply required plugins
      apply plugin: 'maven'
      apply plugin: 'signing'

      // apply conventions and extensions
      project.extensions.create("maven", MavenPluginExtension)

      // configure project
      configurations { archives }

      task('sourcesJar', type: Jar) {
        classifier = 'sources'
        sourceSets.all { from allSource }
      }
      artifacts { archives sourcesJar }

      if(tasks.findByName('javadoc')) {
        task('javadocJar', type:Jar, dependsOn: javadoc) {
          classifier = 'javadoc'
          from javadoc.destinationDir
        }

        artifacts { archives javadocJar }
      }

      if(tasks.findByName('groovydoc')) {
        task('groovydocJar', type:Jar, dependsOn: groovydoc) {
          classifier = 'groovydoc'
          from groovydoc.destinationDir
        }
        
        artifacts { archives groovydocJar }
      }

      signing {
        required { maven.release && gradle.taskGraph.hasTask("uploadArchives") }
        sign configurations.archives
      }

      install {
        group 'maven'
        description 'Install this artifact into your local maven repository'

        repositories {
          mavenInstaller {
            afterEvaluate {
              configurePom(project, pom);
            }
          }
        }
      }

      uploadArchives {
        group 'maven'
        description = "Deploys this artifact to your configured maven repository"

        repositories {
          mavenDeployer {
            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

            setUniqueVersion(false)

            afterEvaluate {
              configuration = configurations.archives
              repository(url: maven.repository) {
                authentication(userName: maven.username, password: maven.password)
              }

              snapshotRepository(url: maven.snapshotRepository) {
                authentication(userName: maven.username, password: maven.password)
              }

              configurePom(project, pom)
            }
          }
        }
      }



    } // end .with
  }

  void configurePom(def project, def pom) {
    project.with {
      // executes the configuration closures with the specified pom
      project.maven.pomConfigClosures?.each { closure -> pom.project closure }

      if(!maven.release) {
        pom.version = "${project.version}-SNAPSHOT"
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy