Skip to content

Commit 55a045c

Browse files
committed
feat(sdk): setup gradle project structure
relates to STACKITTPR-302
1 parent 22e3474 commit 55a045c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+12736
-11330
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"

.github/workflows/ci.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
push:
7+
branches: ["main"]
8+
9+
jobs:
10+
main:
11+
name: CI
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
version: [11, 17, 21]
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Install java
21+
uses: actions/setup-java@v4
22+
with:
23+
distribution: 'temurin'
24+
java-version: '${{ matrix.version }}'
25+
cache: 'gradle'
26+
27+
- name: Check code format
28+
run: ./gradlew spotlessCheck
29+
30+
- name: Test
31+
run: make test
32+
33+
- name: Build
34+
run: make build
35+
36+
- name: Publish to local maven repo
37+
run: make install
38+

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ gradle-app.setting
3838
# Eclipse Core
3939
.project
4040
# JDT-specific (Eclipse Java Development Tools)
41-
.classpath
41+
.classpath
42+
43+
*.iws
44+
*.iml
45+
*.ipr
46+
.idea

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
build:
2+
@./gradlew build
3+
4+
fmt:
5+
@./gradlew spotlessApply
6+
7+
test:
8+
@./gradlew test
9+
10+
install:
11+
@./gradlew publishToMavenLocal

build.gradle

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
plugins {
2+
id 'java'
3+
id 'maven-publish'
4+
id 'idea'
5+
id 'eclipse'
6+
7+
id 'com.diffplug.spotless' version '6.21.0'
8+
}
9+
10+
11+
allprojects {
12+
apply plugin: 'com.diffplug.spotless'
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
javadoc {
19+
options.tags = [
20+
"http.response.details:a:Http Response Details"
21+
]
22+
}
23+
24+
sourceCompatibility = JavaVersion.VERSION_1_8
25+
targetCompatibility = JavaVersion.VERSION_1_8
26+
27+
tasks.withType(JavaCompile) {
28+
options.encoding = 'UTF-8'
29+
}
30+
31+
spotless {
32+
groovyGradle {
33+
greclipse()
34+
35+
trimTrailingWhitespace()
36+
indentWithTabs()
37+
endWithNewline()
38+
}
39+
format 'misc', {
40+
target '.gitattributes', '.gitignore'
41+
42+
trimTrailingWhitespace()
43+
indentWithTabs()
44+
endWithNewline()
45+
}
46+
java {
47+
googleJavaFormat().aosp()
48+
49+
formatAnnotations()
50+
trimTrailingWhitespace()
51+
indentWithTabs()
52+
endWithNewline()
53+
}
54+
}
55+
}
56+
57+
subprojects {
58+
apply plugin: 'java'
59+
apply plugin: 'maven-publish'
60+
apply plugin: 'idea'
61+
apply plugin: 'eclipse'
62+
63+
group = 'cloud.stackit'
64+
version = 'SNAPSHOT'
65+
66+
afterEvaluate { project ->
67+
// only apply to service sub-projects and core
68+
if (project.path.startsWith(':services:') || project.name == "core" ) {
69+
70+
// override the version of each service with the ones obtained from the VERSION files
71+
def versionFile = project.file("VERSION")
72+
if (versionFile.exists()) {
73+
try {
74+
version = versionFile.text.trim()
75+
} catch (IOException e) {
76+
logger.error("Could not read VERSION file for project '${project.name}': ${e.message}")
77+
}
78+
} else {
79+
logger.warn("VERSION file not found in project '${project.name}'. Skipping version setting.")
80+
}
81+
82+
83+
publishing {
84+
publications {
85+
maven(MavenPublication) {
86+
artifactId = "stackit-sdk-${project.name}"
87+
from components.java
88+
89+
pom {
90+
name.set(project.name)
91+
description.set("STACKIT Java SDK for the ${project.name} service")
92+
url.set("https://github.com/stackitcloud/stackit-sdk-java/tree/main/services/${rootProject.name}")
93+
licenses {
94+
license {
95+
name.set("Apache License, Version 2.0")
96+
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
97+
}
98+
}
99+
developers {
100+
developer {
101+
id.set("stackitcloud") // TODO
102+
name.set("STACKIT Developer Tools")
103+
email.set("[email protected]")
104+
}
105+
}
106+
scm {
107+
connection.set("scm:git:git://github.com/stackitcloud/${rootProject.name}.git")
108+
developerConnection.set("scm:git:ssh://github.com/stackitcloud/${rootProject.name}.git")
109+
url.set("https://github.com/stackitcloud/${rootProject.name}")
110+
}
111+
}
112+
}
113+
}
114+
repositories {
115+
mavenLocal()
116+
}
117+
}
118+
}
119+
}
120+
121+
tasks.withType(Test) {
122+
// Enable JUnit 5 (Gradle 4.6+).
123+
useJUnitPlatform()
124+
125+
// Always run tests, even when nothing changed.
126+
dependsOn 'cleanTest'
127+
128+
// Show test results.
129+
testLogging {
130+
events "passed", "skipped", "failed"
131+
}
132+
}
133+
134+
dependencies {
135+
if (project.path != ':core') {
136+
// prevent circular dependency
137+
implementation project(':core')
138+
}
139+
}
140+
}

core/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1-SNAPSHOT

core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package cloud.stackit.sdk.core;
2+
3+
public class CoreDummy {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies {
2+
implementation project (':services:resourcemanager')
3+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cloud.stackit.sdk.resourcemanager.examples;
2+
3+
import cloud.stackit.sdk.resourcemanager.ApiClient;
4+
import cloud.stackit.sdk.resourcemanager.ApiException;
5+
import cloud.stackit.sdk.resourcemanager.api.DefaultApi;
6+
import cloud.stackit.sdk.resourcemanager.model.CreateFolderPayload;
7+
import cloud.stackit.sdk.resourcemanager.model.CreateProjectPayload;
8+
import cloud.stackit.sdk.resourcemanager.model.FolderResponse;
9+
import cloud.stackit.sdk.resourcemanager.model.Project;
10+
import java.util.Map;
11+
import java.util.UUID;
12+
13+
class ResourcemanagerExample {
14+
public static void main(String[] args) {
15+
ApiClient apiClient = new ApiClient();
16+
DefaultApi resourceManagerApi = new DefaultApi(apiClient);
17+
18+
// replace this with something useful for real use
19+
UUID containerParentId = UUID.randomUUID();
20+
21+
try {
22+
/* create a project */
23+
Project project =
24+
resourceManagerApi.createProject(
25+
new CreateProjectPayload()
26+
.containerParentId(containerParentId.toString())
27+
.labels(Map.ofEntries(Map.entry("foo", "bar"))));
28+
29+
/* create a folder */
30+
FolderResponse folder =
31+
resourceManagerApi.createFolder(
32+
new CreateFolderPayload()
33+
.containerParentId(containerParentId.toString())
34+
.labels(Map.ofEntries(Map.entry("foo", "bar"))));
35+
} catch (ApiException e) {
36+
throw new RuntimeException(e);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)