subprojects {
apply plugin: ‘java’
apply plugin: ‘maven’
apply plugin: ‘maven-publish’ // 应用 Maven 发布插件

repositories {
  mavenCentral()
  maven {
    url 'https://repo1.maven.org/maven2/'
  }
}

compileJava.options.encoding = sourceEncoding
javadoc.options.encoding = sourceEncoding
sourceCompatibility = javaSourceVersion
version = packageVersion

jar {
    manifest {
        // support the eclipse manifest-first style
      from file('META-INF/MANIFEST.MF')
      attributes['Bundle-Vendor'] = packageVendor
      attributes['Bundle-Description'] = packageDescription
      attributes['Bundle-Version'] = project.version
      archiveFileName = "pcolor-${version}.jar"
      }
}



sourceSets {
   main {
      java {
       srcDir 'src'
  }
   }
}

// single build dir - nice but perhaps dangerous.
// buildDir = project(':').file('build')

task diag << {
    sourceSets.all { 
      println "classesDir of " + it.name
      println it.output.classesDir
       println "srcDirs: " + it.allSource.srcDirs
       println "allJava: " + it.allJava*.toString()
    }
}

}

project(‘:de.fhg.igd.pcolor’) {

task packageJavadoc(type: Jar, dependsOn: ‘javadoc’) {
from javadoc.destinationDir
classifier = ‘javadoc’
}

task packageSources(type: Jar, dependsOn: assemble) {
from sourceSets.main.allSource
classifier = ‘sources’

manifest {
  attributes['Bundle-Vendor'] = packageVendor
  attributes['Bundle-Description'] = packageDescription
  attributes['Eclipse-SourceBundle'] = project.name + ';version="' + project.version + '";roots:="."'
  attributes['Bundle-SymbolicName'] = project.name + ".source"
  attributes['Bundle-Version'] = project.version
}

}

// 配置发布到本地仓库
publishing {
publications {
mavenJava(MavenPublication) {
groupId = ‘de.fhg.igd’ // 设置 groupId
artifactId = ‘pcolor’ // 设置 artifactId
version = project.version // 设置 version
from components.java
artifact packageJavadoc
artifact packageSources
}
}
repositories {
maven {
name = ‘localRepo’
url = uri(“${project.buildDir}/repo”)
}
}
}

// include doc and source in build
tasks.build.dependsOn += [packageSources, packageJavadoc]
}

project(‘:de.fhg.igd.pcolor.test’) {
// quick fix for java 8
test.scanForTestClasses = false;

// this is cumulative, i.e. compiled twice but
// this way we don’t need to adapt the test task.
sourceSets {
test {
//from sourceSets.main
java {
srcDir ‘src’
}
}
}
dependencies {
compile project(‘:de.fhg.igd.pcolor’)
compile ‘junit:junit:4+’
}
}

project(‘:de.fhg.igd.pcolor.examples’) {
dependencies {
compile project(‘:de.fhg.igd.pcolor’)
}
}

// last build task (depending on all the subprojects’ build tasks)
task build (dependsOn: subprojects*.build) << {
println “Build complete.”
println “The dist files are now in “ + project(‘:de.fhg.igd.pcolor’).libsDir
}

pcolor-1.4.1.jar : 1.4.1.zip
copy jar to : C:\Users\[username]\.m2\repository\com\example\pcolor\
then add mavenLocal() to build.geadle file’ repositories block