Book Image

Gradle Dependency Management

By : Hubert Klein Ikkink
Book Image

Gradle Dependency Management

By: Hubert Klein Ikkink

Overview of this book

Table of Contents (14 chapters)
Gradle Dependency Management
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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...