Giter Club home page Giter Club logo

how-to-gradle-project-variations's Introduction

how-to-gradle-project-variations

Gradle example for generating dynamic subprojects with variations of the dependency graph.

Building

./gradlew war

Why

Suppose one needs to build a test web application for testing compatibility with an external tool such as a Java agent. It would be helpful to know that this test web application works with various versions of the web framework upon which it was built, so we want to repeat the project build with several versions of the web framework. The simplest way to do this is to introduce a Gradle property to represent the version of the web framework and use this property when defining the project's dependencies. Next, one can simply repeat the build with a shell script.

for version in 4.3.12 4.3.13 4.3.14; do
  ./gradlew war -PspringVersion=$version
done

Proposed Solution: dynamic subprojects

Use settings.gradle to dynamicaly generate subprojects for each of the variations of the web application we want to build.

| how-to-gradle-project-variations
├── app
├── build.gradle
├── settings.gradle
└── variations

The "app" directory contains the web application project

app/
└── src
    └── main
        └── java
            └── com
                └── johnathangilday
                    └── HelloWorldServlet.java

settings.gradle generates a subproject for each of the variations of the servlet-api dependency with which we want to build this project

// define versions of javax.servlet:servlet-api for which to generate variations
of the app
def variations = ['2.3', '2.4', '2.5']

def projects = variations.collect { "${rootProject.name}-${it}" }

// include the app subproject with the servlet definitions
include('app')
// include a subproject for each variation of the servlet-api
include(*projects)

/.gradlew projects shows us the dynamic subprojects generated in the "variations" directory

$ ./gradlew projects

> Task :projects

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'how-to-gradle-project-variations'
+--- Project ':app'
+--- Project ':how-to-gradle-project-variations-2.3'
+--- Project ':how-to-gradle-project-variations-2.4'
\--- Project ':how-to-gradle-project-variations-2.5'

how-to-gradle-project-variations's People

Contributors

gilday avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jporzelt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.