gradle6/gradle7打包常见问题及解决
如果是gradle7,则:
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.6/userguide/tutorial_java_projects.html
*/
plugins {
// Apply the java library plugin to add support for Java
id 'java-library'
// Apply the application plugin to add support for building a CLI application.
id 'application'
}
configurations.api.setCanBeResolved(true)
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:29.0-jre'
// https://mvnrepository.com/artifact/org.owasp.esapi/esapi
api group: 'org.owasp.esapi', name: 'esapi', version: '2.2.2.0' //添加编译到JAR包中
//api files('libs/javafx.controls.jar')
//api fileTree(dir:'libs',includes:['*jar'])
// Use JUnit test framework
testImplementation 'junit:junit:4.13'
}
application {
// Define the main class for the application.
mainClassName = 'mytest.App'
}
jar {
manifest {
attributes 'Main-Class': "mytest.App"
}
from {
//添加依懒到打包文件,配合dependencies下的compile group
configurations.api.collect { it.isDirectory() ? it : zipTree(it) }
}
}
如果是gradle6及以下版本,则:
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.6/userguide/tutorial_java_projects.html
*/
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building a CLI application.
id 'application'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:29.0-jre'
// https://mvnrepository.com/artifact/org.owasp.esapi/esapi
compile group: 'org.owasp.esapi', name: 'esapi', version: '2.2.2.0' //添加编译到JAR包中
//compile files('libs/javafx.controls.jar')
//compile fileTree(dir:'libs',includes:['*jar'])
// Use JUnit test framework
testImplementation 'junit:junit:4.13'
}
application {
// Define the main class for the application.
mainClassName = 'mytest.App'
}
jar {
manifest {
attributes 'Main-Class': "mytest.App"
}
from {
//添加依懒到打包文件,配合dependencies下的compile group
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}