Skip to content

Commit c640773

Browse files
feat(build): maven refactor for maven central (#174)
- Deploy to Maven Central (only `sdk`) see https://central.sonatype.org/publish/publish-portal-maven/ - Removes support for OSSRH and Nexus. see https://central.sonatype.org/register/legacy/ - Maven `develop` profile (default) builds `sdk` and `cmdline` - Maven `stage` profile deploys `sdk` to GitHub Packages (only main branch) - Maven `release` profile deploys `sdk` to Maven Central (only on release, [no snapshots](https://central.sonatype.org/faq/snapshot-releases/)) - `sdk/target/generated-sources` replaces `sdk/src/main/protogen` - adds Maven configuration around license, etc. see https://central.sonatype.org/publish/requirements/#supply-javadoc-and-sources - sources and checksums sdk jar - LICENSE Resolves #173 Resolves #79
1 parent bb325c4 commit c640773

File tree

9 files changed

+289
-172
lines changed

9 files changed

+289
-172
lines changed

.github/workflows/checks.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ jobs:
4343
server-id: github
4444
- name: Maven Verify
4545
run: |
46-
mvn --batch-mode clean install -DskipTests
4746
mvn --batch-mode verify
4847
env:
4948
BUF_INPUT_HTTPS_USERNAME: opentdf-bot

.github/workflows/release.yaml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
branches:
66
- main
7+
release:
8+
types: [created]
79

810
permissions:
911
contents: read
@@ -43,8 +45,41 @@ jobs:
4345
server-password: MAVEN_PASSWORD
4446
gpg-private-key: ${{ secrets.GPG_KEY }}
4547
gpg-passphrase: MAVEN_GPG_PASSPHRASE
46-
- name: Publish package
47-
run: mvn --batch-mode deploy -DskipTests
48+
- name: Publish to GitHub Packages
49+
if: github.ref == 'refs/heads/main'
50+
run: |
51+
mkdir -p $HOME/.m2
52+
cat > $HOME/.m2/settings.xml <<EOF
53+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
54+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
55+
<servers><server>
56+
<id>github-pkg</id>
57+
<username>${{ secrets.GITHUB_USERNAME }}</username>
58+
<password>${{ secrets.GITHUB_TOKEN }}</password>
59+
</server></servers>
60+
</settings>
61+
EOF
62+
mvn --batch-mode deploy -DskipTests -P stage
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
BUF_INPUT_HTTPS_USERNAME: opentdf-bot
66+
BUF_INPUT_HTTPS_PASSWORD: ${{ secrets.PERSONAL_ACCESS_TOKEN_OPENTDF }}
67+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }}
68+
- name: Publish to Maven Central
69+
if: startsWith(github.ref, 'refs/tags/')
70+
run: |
71+
mkdir -p $HOME/.m2
72+
cat > $HOME/.m2/settings.xml <<EOF
73+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
74+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
75+
<servers><server>
76+
<id>central</id>
77+
<username>${{ secrets.MAVEN_USERNAME }}</username>
78+
<password>${{ secrets.MAVEN_PASSWORD }}</password>
79+
</server></servers>
80+
</settings>
81+
EOF
82+
mvn --batch-mode deploy -DskipTests -P release
4883
env:
4984
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5085
BUF_INPUT_HTTPS_USERNAME: opentdf-bot

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The Clear BSD License
2+
3+
Copyright (c) 2021-2022 Virtru Corporation
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below)
7+
provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
* Neither the name of Virtru Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without
13+
specific prior written permission.
14+
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
15+
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
17+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
18+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ import java.io.InputStream;
2525
import java.io.FileInputStream;
2626

2727
public class Example {
28-
public static void main(String args[]) {
28+
public static void main(String[] args) {
2929
SDK sdk =
3030
new SDKBuilder
3131
.clientSecret("myClient", "token")
3232
.platformEndpoint("https://your.cluster/")
3333
.build();
3434
// Encrypt a file
3535
try (InputStream in = new FileInputStream("input.plaintext")) {
36-
Config c = Config.newTDFConfig(Config.withDataAttributes("attr1", "attr2"))
36+
Config c = Config.newTDFConfig(Config.withDataAttributes("attr1", "attr2"));
3737
new TDF().createTDF(in, System.out, tdfConfig, sdk.getServices().kas());
3838
}
3939

@@ -43,7 +43,7 @@ public class Example {
4343
TDF.Reader reader = new TDF().loadTDF(in, sdk.getServices().kas());
4444
reader.readPayload(System.out);
4545
}
46-
}
46+
}}
4747
```
4848

4949
### Cryptography Library
@@ -70,5 +70,16 @@ Use the SDKBuilder.withSSL... methods to build an SDKBuilder with:
7070

7171
### Maven Modules
7272
- cmdline: Command line utility
73-
- protocol: Buf generated source code from opentdf proto definitions
7473
- sdk: The OpenTDF Java SDK
74+
75+
### Buf
76+
77+
Create an account, link with GitHub, under User setting, Create a `token`
78+
79+
```shell
80+
[INFO] --- antrun:3.1.0:run (generateSources) @ sdk ---
81+
[INFO] Executing tasks
82+
[INFO] [exec] Failure: too many requests
83+
[INFO] [exec]
84+
[INFO] [exec] Please see https://buf.build/docs/bsr/rate-limits for details about BSR rate limiting.
85+
```

cmdline/pom.xml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
3636
<mainClass>io.opentdf.platform.TDF</mainClass>
3737
<manifestEntries>
38-
<Implementation-Version>${version}</Implementation-Version>
38+
<Implementation-Version>${project.version}</Implementation-Version>
3939
<Main-Class>io.opentdf.platform.TDF</Main-Class>
4040
</manifestEntries>
4141
</transformer>
@@ -56,16 +56,6 @@
5656
</execution>
5757
</executions>
5858
</plugin>
59-
60-
<!-- Skip deployment for this child module -->
61-
<plugin>
62-
<groupId>org.apache.maven.plugins</groupId>
63-
<artifactId>maven-deploy-plugin</artifactId>
64-
<version>3.1.1</version>
65-
<configuration>
66-
<skip>true</skip>
67-
</configuration>
68-
</plugin>
6959
</plugins>
7060
</build>
7161
<dependencies>

pom.xml

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
<groupId>io.opentdf.platform</groupId>
99
<artifactId>sdk-pom</artifactId>
1010
<version>0.7.0-SNAPSHOT</version>
11-
<name>sdk-pom</name>
11+
<name>io.opentdf.platform:sdk-pom</name>
12+
<description>OpenTDF Java SDK</description>
13+
<url>https://github.com/opentdf/java-sdk</url>
1214
<packaging>pom</packaging>
1315
<properties>
1416
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -19,6 +21,18 @@
1921
<protobuf.version>3.25.3</protobuf.version>
2022
<sslcontext.version>8.3.5</sslcontext.version>
2123
</properties>
24+
<licenses>
25+
<license>
26+
<name>BSD 3-Clause Clear License</name>
27+
<url>https://spdx.org/licenses/BSD-3-Clause-Clear.html</url>
28+
</license>
29+
</licenses>
30+
<developers>
31+
<developer>
32+
<organization>Virtru</organization>
33+
<organizationUrl>https://www.virtru.com</organizationUrl>
34+
</developer>
35+
</developers>
2236
<scm>
2337
<connection>scm:git:https://github.com/opentdf/java-sdk.git</connection>
2438
<developerConnection>scm:git:git@github.com:opentdf/java-sdk.git</developerConnection>
@@ -57,18 +71,6 @@
5771
<version>1.18.30</version>
5872
<scope>provided</scope>
5973
</dependency>
60-
<dependency>
61-
<groupId>org.mockito</groupId>
62-
<artifactId>mockito-core</artifactId>
63-
<version>5.2.0</version>
64-
<scope>test</scope>
65-
</dependency>
66-
<dependency>
67-
<groupId>org.mockito</groupId>
68-
<artifactId>mockito-junit-jupiter</artifactId>
69-
<version>5.2.0</version>
70-
<scope>test</scope>
71-
</dependency>
7274
<dependency>
7375
<groupId>org.apache.maven.plugin-tools</groupId>
7476
<artifactId>maven-plugin-annotations</artifactId>
@@ -129,10 +131,6 @@
129131
</plugin>
130132
<!-- default lifecycle, jar packaging: see
131133
https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
132-
<plugin>
133-
<artifactId>maven-resources-plugin</artifactId>
134-
<version>3.0.2</version>
135-
</plugin>
136134
<plugin>
137135
<artifactId>maven-compiler-plugin</artifactId>
138136
<version>3.8.0</version>
@@ -149,18 +147,10 @@
149147
<artifactId>maven-install-plugin</artifactId>
150148
<version>2.5.2</version>
151149
</plugin>
152-
<plugin>
153-
<artifactId>maven-deploy-plugin</artifactId>
154-
<version>2.8.2</version>
155-
</plugin>
156150
<plugin>
157151
<artifactId>maven-gpg-plugin</artifactId>
158152
<version>3.2.3</version>
159153
</plugin>
160-
<plugin>
161-
<artifactId>nexus-staging-maven-plugin</artifactId>
162-
<version>1.7.0</version>
163-
</plugin>
164154
<!-- site lifecycle, see
165155
https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
166156
<plugin>
@@ -208,23 +198,6 @@
208198
</gpgArguments>
209199
</configuration>
210200
</plugin>
211-
<!-- Plugin for Deploying -->
212-
<plugin>
213-
<groupId>org.apache.maven.plugins</groupId>
214-
<artifactId>maven-deploy-plugin</artifactId>
215-
</plugin>
216-
<!-- Plugin for Nexus Staging -->
217-
<plugin>
218-
<groupId>org.sonatype.plugins</groupId>
219-
<artifactId>nexus-staging-maven-plugin</artifactId>
220-
<version>1.7.0</version>
221-
<extensions>true</extensions>
222-
<configuration>
223-
<serverId>ossrh</serverId>
224-
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
225-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
226-
</configuration>
227-
</plugin>
228201
<plugin>
229202
<groupId>org.apache.maven.plugins</groupId>
230203
<artifactId>maven-enforcer-plugin</artifactId>
@@ -264,44 +237,72 @@
264237
</execution>
265238
</executions>
266239
</plugin>
240+
<!-- Exclude from lifecycle, phase none -->
241+
<plugin>
242+
<groupId>org.apache.maven.plugins</groupId>
243+
<artifactId>maven-deploy-plugin</artifactId>
244+
<version>3.1.1</version>
245+
<executions>
246+
<execution>
247+
<id>default-deploy</id>
248+
<phase>none</phase>
249+
</execution>
250+
</executions>
251+
</plugin>
267252
</plugins>
268253
</build>
269254
<profiles>
270255
<profile>
271-
<id>ghcr</id>
256+
<id>develop</id>
257+
<modules>
258+
<module>sdk</module>
259+
<module>cmdline</module>
260+
</modules>
272261
<activation>
273262
<activeByDefault>true</activeByDefault>
274263
</activation>
264+
</profile>
265+
<profile>
266+
<id>stage</id>
267+
<modules>
268+
<module>sdk</module>
269+
</modules>
270+
<activation>
271+
<activeByDefault>false</activeByDefault>
272+
</activation>
275273
<distributionManagement>
276274
<repository>
277-
<id>github</id>
278-
<name>ghcr</name>
275+
<id>github-pkg</id>
276+
<name>GitHub opentdf Apache Maven Packages</name>
279277
<url>https://maven.pkg.github.com/opentdf/java-sdk</url>
280278
</repository>
281-
<snapshotRepository>
282-
<id>github</id>
283-
<name>ghcr</name>
284-
<url>https://maven.pkg.github.com/opentdf/java-sdk</url>
285-
</snapshotRepository>
286279
</distributionManagement>
287280
</profile>
288281
<profile>
289-
<id>ossrh</id>
282+
<id>release</id>
283+
<modules>
284+
<module>sdk</module>
285+
</modules>
290286
<activation>
291-
<activeByDefault>true</activeByDefault>
287+
<activeByDefault>false</activeByDefault>
292288
</activation>
293-
<distributionManagement>
294-
<repository>
295-
<id>ossrh</id>
296-
<name>sonatype</name>
297-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
298-
</repository>
299-
<snapshotRepository>
300-
<id>ossrh</id>
301-
<name>sonatype</name>
302-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
303-
</snapshotRepository>
304-
</distributionManagement>
289+
<build>
290+
<plugins>
291+
<!-- Publish to Maven Central Deploy -->
292+
<plugin>
293+
<groupId>org.sonatype.central</groupId>
294+
<artifactId>central-publishing-maven-plugin</artifactId>
295+
<version>0.6.0</version>
296+
<extensions>true</extensions>
297+
<configuration>
298+
<autoPublish>true</autoPublish>
299+
<waitUntil>published</waitUntil>
300+
<!-- defined in settings.xml -->
301+
<publishingServerId>central</publishingServerId>
302+
</configuration>
303+
</plugin>
304+
</plugins>
305+
</build>
305306
</profile>
306307
</profiles>
307308
</project>

buf.gen.yaml renamed to sdk/buf.gen.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ managed:
99
- buf.build/grpc-ecosystem/grpc-gateway
1010
plugins:
1111
- plugin: buf.build/protocolbuffers/java:v25.3
12-
out: sdk/src/main/protogen
12+
out: ./
1313
- plugin: buf.build/grpc/java:v1.61.1
14-
out: sdk/src/main/protogen
14+
out: ./

0 commit comments

Comments
 (0)