-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datahub-protobuf): add support for shadow jar, publish (#5882)
- Loading branch information
1 parent
e7b33c5
commit fe30f54
Showing
10 changed files
with
309 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-94.3 KB
metadata-integration/java/datahub-protobuf-example/libs/datahub-protobuf.jar
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,13 @@ plugins { | |
} | ||
apply plugin: 'java' | ||
apply plugin: 'jacoco' | ||
apply plugin: 'com.github.johnrengelman.shadow' | ||
apply plugin: 'signing' | ||
apply plugin: 'io.codearte.nexus-staging' | ||
apply plugin: 'maven-publish' | ||
import org.apache.tools.ant.filters.ReplaceTokens | ||
|
||
jar.enabled = false // Since we only want to build shadow jars, disabling the regular jar creation | ||
|
||
afterEvaluate { | ||
if (project.plugins.hasPlugin('java')) { | ||
|
@@ -52,4 +59,190 @@ jacocoTestReport { | |
test { | ||
useJUnit() | ||
finalizedBy jacocoTestReport | ||
} | ||
} | ||
|
||
|
||
task checkShadowJar(type: Exec) { | ||
commandLine 'sh', '-c', 'scripts/check_jar.sh' | ||
} | ||
|
||
//mark implementation dependencies which needs to excluded along with transitive dependencies from shadowjar | ||
//functionality is exactly same as "implementation" | ||
configurations { | ||
provided | ||
implementation.extendsFrom provided | ||
} | ||
|
||
def detailedVersionString = "0.0.0-unknown-SNAPSHOT" | ||
def snapshotVersion = false | ||
if (project.hasProperty("releaseVersion")) { | ||
version = releaseVersion | ||
detailedVersionString = releaseVersion | ||
} else { | ||
try { | ||
// apply this plugin in a try-catch block so that we can handle cases without .git directory | ||
apply plugin: "com.palantir.git-version" | ||
def details = versionDetails() | ||
detailedVersionString = gitVersion() | ||
version = details.lastTag | ||
version = version.startsWith("v")? version.substring(1): version | ||
def suffix = details.isCleanTag? "": "-SNAPSHOT" | ||
snapshotVersion = ! details.isCleanTag | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace() | ||
// last fall back | ||
version = detailedVersionString | ||
} | ||
} | ||
// trim version if it is of size 4 to size 3 | ||
def versionParts = version.tokenize(".") | ||
if (versionParts.size() > 3) { | ||
// at-least 4 part version | ||
// we check if the 4th part is a .0 in which case we want to create a release | ||
if (versionParts[3] != '0') { | ||
snapshotVersion = true | ||
} | ||
versionParts = versionParts[0..2] | ||
version = versionParts[0..2].join('.') | ||
} | ||
|
||
if (snapshotVersion) { | ||
if (versionParts[versionParts.size()-1].isInteger()) { | ||
version = versionParts[0..versionParts.size()-2].join('.') + '.' + (versionParts[versionParts.size()-1].toInteger()+1).toString() + "-SNAPSHOT" | ||
} else { | ||
// we are unable to part the last token as an integer, so we just append SNAPSHOT to this version | ||
version = versionParts[0..versionParts.size()-1].join('.') + '-SNAPSHOT' | ||
} | ||
} | ||
|
||
processResources { | ||
filter(ReplaceTokens, tokens:[fullVersion: detailedVersionString]) | ||
} | ||
|
||
|
||
shadowJar { | ||
zip64=true | ||
archiveClassifier = '' | ||
def exclude_modules = project | ||
.configurations | ||
.provided | ||
.resolvedConfiguration | ||
.getLenientConfiguration() | ||
.getAllModuleDependencies() | ||
.collect { | ||
it.name | ||
} | ||
dependencies { | ||
|
||
exclude(dependency { | ||
exclude_modules.contains(it.name) | ||
}) | ||
|
||
} | ||
mergeServiceFiles() | ||
// we relocate namespaces manually, because we want to know exactly which libs we are exposing and why | ||
// we can move to automatic relocation using ConfigureShadowRelocation after we get to a good place on these first | ||
relocate 'com.fasterxml.jackson', 'datahub.shaded.jackson' | ||
relocate 'net.jcip.annotations', 'datahub.shaded.annotations' | ||
relocate 'javassist', 'datahub.shaded.javassist' | ||
relocate 'edu.umd.cs.findbugs', 'datahub.shaded.findbugs' | ||
relocate 'org.antlr', 'datahub.shaded.org.antlr' | ||
relocate 'antlr', 'datahub.shaded.antlr' | ||
relocate 'org.apache.commons', 'datahub.shaded.org.apache.commons' | ||
relocate 'org.apache.http', 'datahub.shaded.org.apache.http' | ||
relocate 'org.reflections', 'datahub.shaded.org.reflections' | ||
relocate 'st4hidden', 'datahub.shaded.st4hidden' | ||
relocate 'org.stringtemplate', 'datahub.shaded.org.stringtemplate' | ||
relocate 'org.abego.treelayout', 'datahub.shaded.treelayout' | ||
relocate 'org.slf4j', 'datahub.shaded.slf4j' | ||
relocate 'com.github.benmanes.caffeine', 'datahub.shaded.com.github.benmanes.caffeine' | ||
relocate 'org.checkerframework', 'datahub.shaded.org.checkerframework' | ||
relocate 'org.jgrapht', 'datahub.shaded.org.jgrapht' | ||
relocate 'org.jheaps', 'datahub.shaded.org.jheaps' | ||
|
||
finalizedBy checkShadowJar | ||
} | ||
|
||
checkShadowJar { | ||
dependsOn shadowJar | ||
} | ||
|
||
assemble { | ||
dependsOn shadowJar | ||
} | ||
|
||
task sourcesJar(type: Jar) { | ||
archiveClassifier = 'sources' | ||
from sourceSets.main.allSource | ||
} | ||
|
||
task javadocJar(type: Jar) { | ||
archiveClassifier = 'javadoc' | ||
from javadoc | ||
} | ||
|
||
|
||
publishing { | ||
publications { | ||
shadow(MavenPublication) { | ||
publication -> project.shadow.component(publication) | ||
pom { | ||
name = 'Datahub Protobuf' | ||
group = 'io.acryl' | ||
artifactId = 'datahub-protobuf' | ||
description = 'DataHub integration with Protobuf schemas for metadata' | ||
url = 'https://datahubproject.io' | ||
artifacts = [ shadowJar, javadocJar, sourcesJar ] | ||
|
||
scm { | ||
connection = 'scm:git:git://github.com/datahub-project/datahub.git' | ||
developerConnection = 'scm:git:ssh://github.com:datahub-project/datahub.git' | ||
url = 'https://github.com/datahub-project/datahub.git' | ||
} | ||
|
||
licenses { | ||
license { | ||
name = 'The Apache License, Version 2.0' | ||
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' | ||
} | ||
} | ||
|
||
developers { | ||
developer { | ||
id = 'datahub' | ||
name = 'Datahub' | ||
email = '[email protected]' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
repositories { | ||
maven { | ||
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" | ||
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" | ||
def ossrhUsername = System.getenv('RELEASE_USERNAME') | ||
def ossrhPassword = System.getenv('RELEASE_PASSWORD') | ||
credentials { | ||
username ossrhUsername | ||
password ossrhPassword | ||
} | ||
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl | ||
} | ||
} | ||
} | ||
|
||
signing { | ||
def signingKey = findProperty("signingKey") | ||
def signingPassword = System.getenv("SIGNING_PASSWORD") | ||
useInMemoryPgpKeys(signingKey, signingPassword) | ||
sign publishing.publications.shadow | ||
} | ||
|
||
nexusStaging { | ||
serverUrl = "https://s01.oss.sonatype.org/service/local/" //required only for projects registered in Sonatype after 2021-02-24 | ||
username = System.getenv("NEXUS_USERNAME") | ||
password = System.getenv("NEXUS_PASSWORD") | ||
} |
48 changes: 48 additions & 0 deletions
48
metadata-integration/java/datahub-protobuf/scripts/check_jar.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# This script checks the shadow jar to ensure that we only have allowed classes being exposed through the jar | ||
jarFiles=$(find build/libs -name "datahub-protobuf*.jar" | grep -v sources | grep -v javadoc) | ||
for jarFile in ${jarFiles}; do | ||
jar -tvf $jarFile |\ | ||
grep -v "datahub/shaded" |\ | ||
grep -v "google/" |\ | ||
grep -v "google/protobuf" |\ | ||
grep -v "protobuf/" |\ | ||
grep -v "mozilla/" |\ | ||
grep -v "META-INF" |\ | ||
grep -v "com/linkedin" |\ | ||
grep -v "com/datahub" |\ | ||
grep -v "datahub" |\ | ||
grep -v "entity-registry" |\ | ||
grep -v "pegasus/" |\ | ||
grep -v "legacyPegasusSchemas/" |\ | ||
grep -v " com/$" |\ | ||
grep -v " org/$" |\ | ||
grep -v " io/$" |\ | ||
grep -v "git.properties" |\ | ||
grep -v "org/springframework" |\ | ||
grep -v "org/aopalliance" |\ | ||
grep -v "javax/" |\ | ||
grep -v "io/swagger" |\ | ||
grep -v "JavaSpring" |\ | ||
grep -v "java-header-style.xml" |\ | ||
grep -v "xml-header-style.xml" |\ | ||
grep -v "license.header" |\ | ||
grep -v "module-info.class" |\ | ||
grep -v "com/google/" |\ | ||
grep -v "org/codehaus/" |\ | ||
grep -v "client.properties" |\ | ||
grep -v "kafka" |\ | ||
grep -v "win/" |\ | ||
grep -v "include/" |\ | ||
grep -v "linux/" |\ | ||
grep -v "darwin" |\ | ||
grep -v "MetadataChangeProposal.avsc" |\ | ||
grep -v "aix" | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "✅ No unexpected class paths found in ${jarFile}" | ||
else | ||
echo "💥 Found unexpected class paths in ${jarFile}" | ||
exit 1 | ||
fi | ||
done | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters