apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.google.protobuf'
apply plugin: 'application'

sourceCompatibility = 1.8
targetCompatibility = 1.8

def grpcVersion = '0.15.0'

sourceSets.main.java.srcDir "/build/generated/source/proto/main/java/"
sourceSets.main.java.srcDir "/build/generated/source/proto/main/grpc/"

buildscript {
  repositories {
    mavenCentral()
    mavenLocal()
	maven {
	   url "https://oss.sonatype.org/content/groups/public/"
	}
	maven {
        url 'http://repo.spring.io/milestone'
    }
    maven {
       url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }    
  }
  dependencies {
    classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.12'
  }
}

repositories {
	mavenCentral()
	mavenLocal()
	maven {
	   url "https://oss.sonatype.org/content/groups/public/"
	}
	maven {
        url 'http://repo.spring.io/milestone'
    }
    maven {
       url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }    
}

eclipse {
	classpath {
	   downloadSources=true
	}
}

dependencies {
	compile([
  				'io.grpc:grpc-netty:0.15.0',
  				'io.grpc:grpc-protobuf:0.15.0',
  				'io.grpc:grpc-stub:0.15.0'
			])
    compile group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
}

protobuf {
  protoc {
    // The version of protoc must match protobuf-java. If you don't depend on
    // protobuf-java directly, you will be transitively depending on the
    // protobuf-java version that grpc depends on.
    artifact = 'com.google.protobuf:protoc:3.0.0-beta-3'
  }
  plugins {
    grpc {
      artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
    }
  }
  generateProtoTasks {
    all()*.plugins {
      grpc {}
    }
  }
}

mainClassName = 'io.grpc.examples.helloworld.HelloWorldServer'

task helloWorldServer(type: CreateStartScripts) {
  mainClassName = 'io.grpc.examples.helloworld.HelloWorldServer'
  applicationName = 'hello-world-server'
  outputDir = new File(project.buildDir, 'tmp')
  classpath = jar.outputs.files + project.configurations.runtime
}

task helloWorldClient(type: CreateStartScripts) {
  mainClassName = 'io.grpc.examples.helloworld.HelloWorldClient'
  applicationName = 'hello-world-client'
  outputDir = new File(project.buildDir, 'tmp')
  classpath = jar.outputs.files + project.configurations.runtime
}

startScripts.enabled = false
