1

I'm trying to build a java library for my other java projects. I'm also trying to learn gradle. There is a tutorial : https://docs.gradle.org/current/samples/sample_building_java_libraries.html shows how to build libraries with gradle.

But somehow when I use gradlew build it always gives me lib-< version >.jar and creates a folder called lib and I can't change it. enter image description here

This is my settings.gradle

rootProject.name = 'myOwnLibrary'
include('lib')

this is my build.gradle (inside lib folder)

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'
}
senko
  • 135
  • 1
  • 10
  • Does this answer your question? [Want to specify jar name and version both in build.gradle](https://stackoverflow.com/questions/31405818/want-to-specify-jar-name-and-version-both-in-build-gradle) – Cisco Nov 21 '20 at 23:06
  • @FranciscoMateo not exactly the same problem, here he can already give a name to jar file other then "lib". In my situation gradle creates a folder named lib and I can't change it My solution was delete that folder and create a new java module. I don't know if there is another way but it worked for me. – senko Nov 24 '20 at 18:57

1 Answers1

1

With Kotlin DSL example, you can add in your tasks jar the following snippet:

tasks.jar {
    manifest {
        attributes(mapOf("Implementation-Title" to rootProject.name,
                         "Implementation-Version" to project.version))
    }
    archiveBaseName.set(rootProject.name)
}

where rootProject.name, is the value localized into settings.gradle.kts file.