buildJavaDependencies builds and install the needed dependencies used to build, package and run the user module. Everything will be done under ModSourceDirPath/dagger-io (m.moduleConfig.genPath()).
( ctx context.Context, introspectionJSON *dagger.File, )
| 143 | // used to build, package and run the user module. |
| 144 | // Everything will be done under ModSourceDirPath/dagger-io (m.moduleConfig.genPath()). |
| 145 | func (m *JavaSdk) buildJavaDependencies( |
| 146 | ctx context.Context, |
| 147 | introspectionJSON *dagger.File, |
| 148 | ) (*dagger.Container, error) { |
| 149 | // We need maven to build the dependencies |
| 150 | ctr, err := m.mvnContainer(ctx) |
| 151 | if err != nil { |
| 152 | return nil, err |
| 153 | } |
| 154 | version, err := m.getDaggerVersionForModule(ctx, introspectionJSON) |
| 155 | if err != nil { |
| 156 | return nil, err |
| 157 | } |
| 158 | return ctr. |
| 159 | // Cache maven dependencies |
| 160 | WithMountedCache("/root/.m2", dag.CacheVolume("sdk-java-maven-m2"), dagger.ContainerWithMountedCacheOpts{Sharing: dagger.CacheSharingModeLocked}). |
| 161 | // Mount the introspection JSON file used to generate the SDK |
| 162 | WithMountedFile("/schema.json", introspectionJSON). |
| 163 | // Copy the SDK source directory, so all the files needed to build the dependencies |
| 164 | WithDirectory(GenPath, m.SDKSourceDir). |
| 165 | WithWorkdir(GenPath). |
| 166 | // Set the version of the dependencies we are building to the version of the introspection file |
| 167 | WithExec(m.mavenCommand( |
| 168 | "mvn", |
| 169 | "versions:set", |
| 170 | "-DgenerateBackupPoms=false", |
| 171 | "-DprocessDependencies=false", |
| 172 | "-DprocessPlugins=false", |
| 173 | fmt.Sprintf("-DnewVersion=%s", version), |
| 174 | )). |
| 175 | // Build and install the java modules one by one |
| 176 | // - dagger-codegen-maven-plugin: this plugin will be used to generate the SDK code, from the introspection file, |
| 177 | // this means including the ability to call other projects (not part of the main dagger SDK) |
| 178 | // - this plugin is only used to build the SDK, the user module doesn't need it |
| 179 | // - dagger-java-annotation-processor: this will read dagger specific annotations (@Module, @Object, @Function) |
| 180 | // and generate the entrypoint to register the module and invoke the functions |
| 181 | // - this processor will be used by the user module to generate the entrypoint, so it's referenced in the user module pom.xml |
| 182 | // - dagger-java-sdk: the actual SDK, where the generated code will be written |
| 183 | // - the user module code only depends on this, it includes all the required types |
| 184 | WithExec(m.mavenCommand( |
| 185 | "mvn", |
| 186 | "--projects", "dagger-codegen-maven-plugin,dagger-java-annotation-processor,dagger-java-sdk", "--also-make", |
| 187 | "clean", "install", |
| 188 | // avoid tests |
| 189 | "-DskipTests", |
| 190 | // specify the introspection json file |
| 191 | "-Ddaggerengine.schema=/schema.json", |
| 192 | )), nil |
| 193 | } |
| 194 | |
| 195 | // addTemplate creates all the necessary files to start a new Java module |
| 196 | func (m *JavaSdk) addTemplate( |
no test coverage detected