You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
4.3 KiB

apply plugin: 'java'
buildscript {
repositories {
maven {
url = uri('https://mvn.fanruan.com/repository/maven-public/')
}
dependencies {
classpath localGroovy()
}
}
}
ext {
/**
* 项目中依赖的jar的路径
* 1.如果依赖的jar需要打包到zip中,放置在lib根目录下
* 2.如果依赖的jar仅仅是编译时需要,防止在lib下子目录下即可
*/
libPath = "$projectDir/../webroot/WEB-INF/lib"
/**
* 是否对插件的class进行加密保护,防止反编译
*/
guard = true
def pluginInfo = getPluginInfo()
pluginPre = "fine-plugin"
pluginName = pluginInfo.id
pluginVersion = pluginInfo.version
outputPath = "$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0/classes"
XMLPath = "$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0"
pluginLibPath = "$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0/lib"
}
group = 'com.fr.plugin'
version = '10.0'
compileJava {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
sourceSets {
main {
java {
destinationDirectory.set(file(outputPath))
}
output.resourcesDir = file(outputPath)
}
}
ant.importBuild("encrypt.xml")
//定义ant变量
ant.projectDir = projectDir
ant.references["compile.classpath"] = ant.path {
fileset(dir: libPath, includes: '**/*.jar')
fileset(dir: ".", includes: "**/*.jar")
}
clean.doFirst {
delete file(outputPath)
delete file("$projectDir/classes")
delete file("$projectDir/transform-classes")
}
classes.dependsOn('clean')
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
task copyFiles(type: Copy, dependsOn: 'classes') {
from outputPath
into "$projectDir/classes"
}
task copy_plugin_config(type: Copy, dependsOn: 'copy_plugin_lib') {
from "$projectDir/plugin.xml"
into XMLPath
}
task copy_plugin_lib(type: Copy) {
from("$projectDir/lib") {
include "*.jar"
}
into file(pluginLibPath)
}
task copy_dependencies(type: Copy) {
from configurations.runtimeClasspath
into file("$projectDir/lib")
exclude "fine-third*", "fine-activator*", "fine-core*", "fine-webui*", "fine-datasource*", "fine-decision*", "fine-schedule*", "fine-swift*", "fine-accumulator*", "fine-report*", "fineio*"
}
task preJar(type: Copy, dependsOn: guard ? 'compile_encrypt_javas' : 'compile_plain_javas') {
from "$projectDir/classes"
into "$projectDir/transform-classes"
include "**/*.*"
}
jar.dependsOn("preJar")
task makeJar(type: Jar, dependsOn: preJar) {
from fileTree(dir: "$projectDir/transform-classes")
archiveBaseName.set(pluginPre)
archiveAppendix.set(pluginName)
archiveVersion.set(pluginVersion)
destinationDirectory = file("$buildDir/libs")
doLast() {
delete file("$projectDir/classes")
delete file("$projectDir/transform-classes")
}
}
task copyFile(type: Copy, dependsOn: ["makeJar"]) {
from "$buildDir/libs"
from("$projectDir/lib") {
include "*.jar"
}
from "$projectDir/plugin.xml"
into file("$buildDir/temp/plugin")
}
task zip(type: Zip, dependsOn: ["copyFile"]) {
from "$buildDir/temp/plugin"
destinationDirectory = file("$buildDir/install")
archiveBaseName.set(pluginPre)
archiveAppendix.set(pluginName)
archiveVersion.set(pluginVersion)
}
//控制build时包含哪些文件,排除哪些文件
processResources {
// exclude everything
// 用*.css没效果
// exclude '**/*.css'
// except this file
// include 'xx.xml'
}
/*读取plugin.xml中的version*/
def getPluginInfo() {
def xmlFile = file("plugin.xml")
if (!xmlFile.exists()) {
return ["id": "none", "version": "1.0.0"]
}
def plugin = new groovy.xml.XmlParser().parse(xmlFile)
def version = plugin.version.text()
def id = plugin.id.text()
return ["id": id, "version": version]
}
repositories {
// mavenLocal()
maven {
url = uri('https://mvn.fanruan.com/repository/maven-public/')
}
}
dependencies {
//使用本地jar
implementation fileTree(dir: 'lib', include: ['**/*.jar'])
// 指定依赖引用
// implementation files("../finekit/build/libs/finekit-10.0.jar")
}