文章目录
- 引资
- 附录
引资
1.示例代码:
/** This file was generated by the Gradle 'init' task.** This project uses @Incubating APIs which are subject to change.*/plugins {id 'java'id 'maven-publish'
// id "io.freefair.lombok" version "8.4"
}repositories {mavenLocal()maven {url = uri('https://repo.maven.apache.org/maven2/')}
}dependencies {implementation 'org.projectlombok:lombok:1.18.10'annotationProcessor 'org.projectlombok:lombok:1.18.10'// compileOnly 'org.projectlombok:lombok:1.18.30'
// annotationProcessor 'org.projectlombok:lombok:1.18.30'
// testCompileOnly 'org.projectlombok:lombok:1.18.30'
// testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'implementation 'org.xbo.hotfix:hotfix-patch:0.3-SNAPSHOT'implementation 'com.beust:jcommander:1.78'implementation 'org.apache.maven.plugins:maven-compiler-plugin:3.11.0'implementation 'org.apache.maven.plugins:maven-assembly-plugin:3.6.0'testImplementation 'junit:junit:4.12'
}group = 'org.xbo.hotfix'
version = '0.3-SNAPSHOT'
description = 'hotfix-agent'
java.sourceCompatibility = JavaVersion.VERSION_1_8tasks.register('copyJars', Copy) {from configurations.runtimeClasspathinto "$buildDir/libs/"
}// gradle >= 5
jar {manifest {attributes 'Manifest-Version' : '1.0'attributes 'Implementation-Title': 'hotfix-agent'attributes 'Implementation-Version': "0.3-SNAPSHOT"attributes 'Main-Class': 'org.xbo.hotfix.agent.Installer'attributes 'Premain-Class': 'org.xbo.hotfix.agent.Installer'attributes "Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ')+ " ../config"}
}jar.dependsOn += copyJars/* gradle <= 4
jar {manifest {attributes 'Manifest-Version' : '1.0'attributes 'Implementation-Title': 'litchi web server'attributes 'Implementation-Version': 1.0attributes 'Main-Class': 'com.kd.webserver.WebLauncher'attributes "Class-Path": configurations.compile.collect { it.getName() }.join(' ')+ " ../config"}
}
*/publishing {publications {maven(MavenPublication) {from(components.java)}}
}tasks.withType(JavaCompile).configureEach {options.encoding = 'UTF-8'
}
2.其他jar打包:
// with >= gradle v6
tasks.register('copyJars', Copy) {from configurations.runtimeClasspathinto "$buildDir/libs/"
}// with <= gradle v4
tasks.register('copyDownloadableDepsToLibs', Copy) {from configurations.compileinto 'build/libs'
}
附录
[1] Yumenokanata/build.gradle
[2] javaagent使用指南