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

Creating artifacts


We saw how to define artifacts, but we also need to create artifacts in our build files. We can either use an archive task to create the artifact or a file can be an artifact. Most of the time, when we use Gradle in a Java project, we build an archive with compiled classes and resources. Actually, the Java plugin adds a jar task to our project that will just do that. The JAR file created is then added to the archives configuration.

In the next example build file, we will use the Java plugin and simply rely on the default artifact configuration and tasks. The following code shows this:

apply plugin: 'java'

// Define project properties.
group = 'com.mrhaki.sample'
version = '2.1'
archivesBaseName = 'sample'

// Extra task to check the artifacts.
task artifactsInfo << {
  configurations
    .findByName('archives')
    .allArtifacts
    .each { artifact ->
      println artifact.file.name
    }
}

We can now run the buildArchives task and check the artifacts with the...