|
8 | 8 | "path/filepath"
|
9 | 9 | "runtime"
|
10 | 10 | "strings"
|
11 |
| - |
12 |
| - "github.com/otiai10/copy" |
13 | 11 | )
|
14 | 12 |
|
15 | 13 | // BuildJavaProgramOptions are options for BuildJavaProgram.
|
@@ -82,25 +80,12 @@ func BuildJavaProgram(ctx context.Context, options BuildJavaProgramOptions) (*Ja
|
82 | 80 |
|
83 | 81 | // If we depend on SDK via path, built it and get the JAR
|
84 | 82 | 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 |
| - } |
99 | 83 |
|
100 | 84 | // Create build.gradle and settings.gradle
|
101 | 85 | temporalSDKDependency := ""
|
102 | 86 | 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,'" |
104 | 89 | } else if options.Version != "" {
|
105 | 90 | temporalSDKDependency = fmt.Sprintf("implementation 'io.temporal:temporal-sdk:%v'",
|
106 | 91 | strings.TrimPrefix(options.Version, "v"))
|
@@ -128,7 +113,22 @@ application {
|
128 | 113 | if err := os.WriteFile(filepath.Join(dir, "build.gradle"), []byte(buildGradle), 0644); err != nil {
|
129 | 114 | return nil, fmt.Errorf("failed writing build.gradle: %w", err)
|
130 | 115 | }
|
| 116 | + |
131 | 117 | 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 | + } |
132 | 132 | if err := os.WriteFile(filepath.Join(dir, "settings.gradle"), []byte(settingsGradle), 0644); err != nil {
|
133 | 133 | return nil, fmt.Errorf("failed writing settings.gradle: %w", err)
|
134 | 134 | }
|
|
0 commit comments