使用 gradle 构建时如何更改 java 库的名称?
How to change name of java library when build with gradle?
我正在尝试为我的其他 java 项目构建一个 java 库。我也在努力学习gradle。有一个教程:https://docs.gradle.org/current/samples/sample_building_java_libraries.html 展示了如何使用 gradle.
构建库
但不知何故,当我使用 gradlew build 时,它总是给我 lib-< version >.jar 并创建一个名为 lib 的文件夹,我无法更改它。
这是我的settings.gradle
rootProject.name = 'myOwnLibrary'
include('lib')
这是我的 build.gradle(在 lib 文件夹中)
plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
}
version = "0.1.1"
tasks.named('jar') {
manifest {
attributes('Implementation-Title': project.name,
'Implementation-Version': project.version)
}
}
repositories {
// Use JCenter for resolving dependencies.
jcenter()
}
dependencies {
// Use JUnit test framework.
testImplementation 'junit:junit:4.13'
// This dependency is exported to consumers, that is to say, found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:29.0-jre'
}
使用 Kotlin DSL 示例,您可以在任务 jar 中添加以下代码段:
tasks.jar {
manifest {
attributes(mapOf("Implementation-Title" to rootProject.name,
"Implementation-Version" to project.version))
}
archiveBaseName.set(rootProject.name)
}
其中 rootProject.name 是本地化到 settings.gradle.kts 文件中的值。
我正在尝试为我的其他 java 项目构建一个 java 库。我也在努力学习gradle。有一个教程:https://docs.gradle.org/current/samples/sample_building_java_libraries.html 展示了如何使用 gradle.
构建库但不知何故,当我使用 gradlew build 时,它总是给我 lib-< version >.jar 并创建一个名为 lib 的文件夹,我无法更改它。
这是我的settings.gradle
rootProject.name = 'myOwnLibrary'
include('lib')
这是我的 build.gradle(在 lib 文件夹中)
plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
}
version = "0.1.1"
tasks.named('jar') {
manifest {
attributes('Implementation-Title': project.name,
'Implementation-Version': project.version)
}
}
repositories {
// Use JCenter for resolving dependencies.
jcenter()
}
dependencies {
// Use JUnit test framework.
testImplementation 'junit:junit:4.13'
// This dependency is exported to consumers, that is to say, found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:29.0-jre'
}
使用 Kotlin DSL 示例,您可以在任务 jar 中添加以下代码段:
tasks.jar {
manifest {
attributes(mapOf("Implementation-Title" to rootProject.name,
"Implementation-Version" to project.version))
}
archiveBaseName.set(rootProject.name)
}
其中 rootProject.name 是本地化到 settings.gradle.kts 文件中的值。