Using software components

Besides the artifact method and the artifacts property, we can also use the from method inside a publications configuration block. We specify SoftwareComponent for Gradle as an argument to the from method. The java plugin adds SoftwareComponent with the name java, and it includes the jar artifact and all runtime dependencies. The war plugin adds the war artifact as SoftwareComponent. SoftwareComponent is a part of the Gradle build model that defines a piece of code that depends on other code or is a dependency for other code.

In the next example build file, we will apply the war plugin to our project, which will implicitly add the java plugin. We also define two publications, each using SoftwareComponent from both plugins. The following code shows this:

apply plugin: 'maven-publish'
apply plugin: 'war'


publishing {

  publications {

    // First publication with
    // the name javaJar, contains
    // the artifact created by the
    // jar task.
    javaJar(MavenPublication) {
      from components.java
    }

    // Second publication with
    // the name webWar, contains
    // the artifact created by
    // the war task.
    webWar(MavenPublication) {
      from components.web
    }

  }

}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.116.51