Skip to content

Commit

Permalink
Include NOTICE+LICENSE in every jar
Browse files Browse the repository at this point in the history
Adds the contents of `LICENSE` and `NOTICE` to every jar using the following patterns:
* `META-INF/licenses/<maven-group-id>/<maven-artifact-id>-<version>/LICENSE`
* `META-INF/licenses/<maven-group-id>/<maven-artifact-id>-<version>/NOTICE`
  • Loading branch information
snazy committed Feb 3, 2025
1 parent b7d7e63 commit 25a47d9
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ out/
# gradle
.gradle/
build/
.kotlin

# Ignore Gradle wrapper jar file
gradle/wrapper/gradle-wrapper.jar
Expand Down
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
LICENSE applicable to Nessie source
-----------------------------------
Nessie LICENSE
--------------

Apache License
Version 2.0, January 2004
Expand Down
4 changes: 2 additions & 2 deletions LICENSE-BINARY-DIST
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
LICENSE applicable to Nessie binary distributions
-------------------------------------------------
LICENSE applicable to Nessie executables and containers
-------------------------------------------------------

Apache License
Version 2.0, January 2004
Expand Down
10 changes: 5 additions & 5 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NOTICE applicable to Nessie source
----------------------------------
Nessie NOTICE
-------------

Dremio
Copyright 2015-2025 Dremio Corporation
Expand Down Expand Up @@ -34,15 +34,15 @@ Copyright The Apache Software Foundation
Netty
Copyright The Netty Project

This product includes additional software licensed under the terms
of the following licenses:
This product may include or have transitive dependencies to additional software
licensed under the terms of the following licenses:
* Apache Software License, Version 2.0
* Creative Commons 1.0 Universal
* Eclipse Distribution License, Version 1.0
* Eclipse Public License, Version 1.0
* Eclipse Public License, Version 2.0

See also the LICENSE file for Nessie source.
See also the LICENSE file.

The Nessie web site provides aggregated license reports for recent Nessie
binary distributions, available at https://projectnessie.org/docs/ and
Expand Down
4 changes: 2 additions & 2 deletions NOTICE-BINARY-DIST
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NOTICE applicable to Nessie binary distributions
------------------------------------------------
NOTICE applicable to Nessie executables and containers
------------------------------------------------------

Dremio
Copyright 2015-2025 Dremio Corporation
Expand Down
41 changes: 35 additions & 6 deletions build-logic/src/main/kotlin/Utilities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@ import java.io.File
import java.lang.IllegalArgumentException
import java.lang.IllegalStateException
import java.util.Properties
import org.gradle.api.Action
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.UnknownProjectException
import org.gradle.api.*
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileTree
import org.gradle.api.invocation.Gradle
import org.gradle.api.logging.LogLevel
import org.gradle.api.provider.ListProperty
import org.gradle.api.resources.TextResource
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.*
import org.gradle.api.tasks.testing.Test
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainService
Expand Down Expand Up @@ -385,3 +383,34 @@ class ReplaceInFiles(val files: FileTree, val replacements: Map<String, String>)
}
}
}

@CacheableTask
abstract class GeneratePomProperties : DefaultTask() {
@Suppress("unused") @get:Input abstract val pomInputs: ListProperty<String>

@get:OutputDirectory abstract val destinationDir: DirectoryProperty

init {
pomInputs.convention(listOf(project.group.toString(), project.name, project.version.toString()))
destinationDir.convention(project.layout.buildDirectory.dir("generated/pom-properties"))
}

@TaskAction
fun generate() {
val buildDir = destinationDir.get().asFile
buildDir.deleteRecursively()
val targetDir = buildDir.resolve("META-INF/maven/${project.group}/${project.name}")
targetDir.mkdirs()
targetDir
.resolve("pom.properties")
.writeText(
"""
# Generated by the Nessie build.
groupId=${project.group}
artifactId=${project.name}
version=${project.version}
"""
.trimIndent()
)
}
}
42 changes: 42 additions & 0 deletions build-logic/src/main/kotlin/nessie-common-java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,45 @@ plugins {
id("nessie-java")
id("nessie-testing")
}

if (project.hasProperty("release") || project.hasProperty("jarWithGitInfo")) {
/**
* Adds convenient, but not strictly necessary information to each generated "main" jar.
*
* This includes `pom.properties` and `pom.xml` files where Maven places those, in
* `META-INF/maven/group-id/artifact-id/`. Also adds the `NOTICE` and `LICENSE` files in
* `META-INF`, which makes it easier for license scanners.
*/
plugins.withType(JavaLibraryPlugin::class.java) {
val generatePomProperties =
tasks.register("generatePomProperties", GeneratePomProperties::class.java) {}

val additionalJarContent =
tasks.register("additionalJarContent", Sync::class.java) {
// Have to manually declare the inputs of this task here on top of the from/include below
inputs.files(rootProject.layout.files("LICENSE", "NOTICE"))
inputs.property("GAV", "${project.group}:${project.name}:${project.version}")
dependsOn("generatePomFileForMavenPublication")
from(rootProject.rootDir) {
include("LICENSE", "NOTICE")
eachFile {
this.path =
"META-INF/licenses/${project.group}/${project.name}-${project.version}/$sourceName"
}
}
from(tasks.named("generatePomFileForMavenPublication")) {
include("pom-default.xml")
eachFile { this.path = "META-INF/maven/${project.group}/${project.name}/pom.xml" }
}
into(layout.buildDirectory.dir("license-for-jar"))
}

tasks.named("processResources") { dependsOn(additionalJarContent) }

val sourceSets: SourceSetContainer by project
sourceSets.named("main") {
resources.srcDir(additionalJarContent)
resources.srcDir(generatePomProperties)
}
}
}
4 changes: 2 additions & 2 deletions build-logic/src/main/kotlin/nessie-common-src.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ plugins.withType<JavaPlugin>().configureEach {
// Adds Git/Build/System related information to the generated jars, if the `release` project
// property is present. Do not add that information in development builds, so that the
// generated jars are still cachable for Gradle.
if (project.hasProperty("release")) {
if (project.hasProperty("release") || project.hasProperty("jarWithGitInfo")) {
tasks.withType<Jar>().configureEach {
manifest { MemoizedGitInfo.gitInfo(rootProject, attributes) }
}
Expand All @@ -193,7 +193,7 @@ class MemoizedGitInfo {
}

fun gitInfo(rootProject: Project): Map<String, String> {
if (!rootProject.hasProperty("release")) {
if (!rootProject.hasProperty("release") && !rootProject.hasProperty("jarWithGitInfo")) {
return emptyMap()
}

Expand Down

0 comments on commit 25a47d9

Please sign in to comment.