Skip to content

Commit fa5255b

Browse files
authored
Make depending on SDK by path actually work with compile errors (temporalio#495)
1 parent 0b55439 commit fa5255b

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

Diff for: sdkbuild/java.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"path/filepath"
99
"runtime"
1010
"strings"
11-
12-
"github.com/otiai10/copy"
1311
)
1412

1513
// BuildJavaProgramOptions are options for BuildJavaProgram.
@@ -82,25 +80,12 @@ func BuildJavaProgram(ctx context.Context, options BuildJavaProgramOptions) (*Ja
8280

8381
// If we depend on SDK via path, built it and get the JAR
8482
isPathDep := strings.ContainsAny(options.Version, `/\`)
85-
if isPathDep {
86-
cmd := j.buildGradleCommand(ctx, options.Version, false, options.ApplyToCommand, "jar", "gatherRuntimeDeps")
87-
if err := cmd.Run(); err != nil {
88-
return nil, fmt.Errorf("failed building Java SDK: %w", err)
89-
}
90-
// Copy JARs to sdkjars dir
91-
sdkJarsDir := filepath.Join(dir, "sdkjars")
92-
if err := copy.Copy(filepath.Join(options.Version, "temporal-sdk/build/libs"), sdkJarsDir); err != nil {
93-
return nil, fmt.Errorf("failed copying lib JARs: %w", err)
94-
}
95-
if err := copy.Copy(filepath.Join(options.Version, "temporal-sdk/build/runtimeDeps"), sdkJarsDir); err != nil {
96-
return nil, fmt.Errorf("failed copying runtime JARs: %w", err)
97-
}
98-
}
9983

10084
// Create build.gradle and settings.gradle
10185
temporalSDKDependency := ""
10286
if isPathDep {
103-
temporalSDKDependency = "implementation fileTree(dir: 'sdkjars', include: ['*.jar'])"
87+
// Any version will do here with path dep since we're going to substitute it with the project
88+
temporalSDKDependency = "implementation 'io.temporal:temporal-sdk:[1.0,'"
10489
} else if options.Version != "" {
10590
temporalSDKDependency = fmt.Sprintf("implementation 'io.temporal:temporal-sdk:%v'",
10691
strings.TrimPrefix(options.Version, "v"))
@@ -128,7 +113,22 @@ application {
128113
if err := os.WriteFile(filepath.Join(dir, "build.gradle"), []byte(buildGradle), 0644); err != nil {
129114
return nil, fmt.Errorf("failed writing build.gradle: %w", err)
130115
}
116+
131117
settingsGradle := fmt.Sprintf("rootProject.name = '%v'", filepath.Base(dir))
118+
// If dependency is a path dep, include the SDK gradle project and substitute the sdk dependency
119+
if isPathDep {
120+
asAbsPath, err := filepath.Abs(options.Version)
121+
if err != nil {
122+
return nil, fmt.Errorf("failed getting absolute path of by-path-version: %w", err)
123+
}
124+
settingsGradle += `
125+
includeBuild('` + asAbsPath + `') {
126+
dependencySubstitution {
127+
substitute module('io.temporal:temporal-sdk') using project(':temporal-sdk')
128+
}
129+
}
130+
`
131+
}
132132
if err := os.WriteFile(filepath.Join(dir, "settings.gradle"), []byte(settingsGradle), 0644); err != nil {
133133
return nil, fmt.Errorf("failed writing settings.gradle: %w", err)
134134
}

0 commit comments

Comments
 (0)