1

I would like to use Gradle to build a java project and I would like to structure it as follows.

  • Core Library
  • Web App (war plugin)
  • Server (application plugin)
  • Client
  • Client War (war plugin)

The Web App, Server, and Client all depend on core. The Server depends on the Web App because it is going to serve it as the admin page using embedded Jetty. The Client War depends on the Client. The Client War is to be deployed to a web server for distribution of the client as a web start application.

What I would like to know is how can I tell the Server project that it depends on the Web App and needs to copy it into the proper location in it's distribution structure. I would also like to know how I can tell the Client War project to depend on the Client project and to copy the Client jar and all of it's dependencies into the proper location to build the war archive.

I plan to use the application plugin for the Server so under <root>/src/dist there will be a webapp directory where the one or possibly more web apps will reside. It is expected that the files contained in the webapp directory will be war files.

This is a new project so it can follow the standard build conventions of Gradle and the project layout expected by Gradle.

Ideally at some point the Client artifacts will be published to an internal Artifactory or Sonatype Nexus repository so that the Client War can be built with version support.

So far I have found the following resources.

Zixradoom
  • 917
  • 1
  • 10
  • 24
  • Possible duplicate of [Gradle and Multi-Project structure](http://stackoverflow.com/questions/17536652/gradle-and-multi-project-structure) – Ethan Feb 06 '16 at 23:00
  • I am not attempting to unify the build under a single build.gradle file. I would describe it as defining a new dependency classification ( example compile, testRuntime, myCustomTransient, packagedApp ) that I will want to do specail processing on. – Zixradoom Feb 07 '16 at 19:34
  • That post isn't about a single build.gradle. You're looking for configurations. – Ethan Feb 07 '16 at 19:51

1 Answers1

0

I believe I figured out the Web App dependency part of my problem. The Client War is a lost cause for now.

Server build.gradle

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'application'

targetCompatibility = 1.8
sourceCompatibility = 1.8
version = '0.0.1-SNAPSHOT'
group = 'com.s2d'
mainClassName = 'com.simonsoftwaredesign.example.echo.server.EchoServerApp'

repositories {
  mavenCentral()
}

configurations {
  webContainer
}

dependencies {
  compile project(':echo-core')
  compile group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.3.7.v20160115'
  compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '9.3.7.v20160115'

  webContainer project(path: ':echo-admin', configuration: 'warApp')
}

task copyWebApps(dependsOn: configurations.webContainer, type: Copy) {
  from { configurations.webContainer.collect { it } }
  // I don't like how this is hard coded
  // but I am not sure how to fix it
  into 'src/main/dist/webapp'
}

installDist.dependsOn copyWebApps
distZip.dependsOn copyWebApps
distTar.dependsOn copyWebApps

Web App build.gradle

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'war'

targetCompatibility = 1.8
sourceCompatibility = 1.8
version = '0.0.1-SNAPSHOT'
group = 'com.s2d'

configurations {
  warApp
}

repositories {
  mavenCentral()
}

dependencies {
  providedCompile project(':echo-core')
  providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
}

artifacts {
  warApp war
}

Gradle projects depending on artifacts created by sibling projects

Community
  • 1
  • 1
Zixradoom
  • 917
  • 1
  • 10
  • 24