Skip to content

Commit e253eec

Browse files
ludochgae-java-bot
authored andcommitted
Add Gradle instructions for using latest App Engine runtime bits.
PiperOrigin-RevId: 890507397 Change-Id: I2b30fb9efecbc55b3811bd950710c294eea0915f
1 parent 40e741f commit e253eec

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

TRYLATESTBITSINPROD.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,87 @@ sed -i '/<\/plugins>/i \
278278
echo "Updated $POM_FILE"
279279
```
280280

281+
282+
## For the Gradle build system
283+
284+
If you are using the Gradle build system, you can apply the following changes to your build script.
285+
286+
These instructions configure the `war` task to do two important things:
287+
1. **Move the jars to the top of the WAR directory:** The `into("")` (or `into('.')`) block combined with `eachFile { path = name }` extracts the jars and flattens the directory structure, placing them directly in the root of the generated WAR.
288+
2. **Rename the jars:** The `rename` block strips the version string (e.g., `-5.0.1-SNAPSHOT`) from the extracted jars so their names exactly match the `-Djava.class.path=runtime-main.jar` argument specified in the `appengine-web.xml` entrypoint.
289+
290+
### Kotlin
291+
```
292+
import org.gradle.api.tasks.bundling.War
293+
294+
// 1. Define the target runtime version
295+
val gaeRuntimeVersion = "5.0.1-SNAPSHOT" // Change this to your desired version
296+
297+
// 2. Create a custom configuration for the runtime zip
298+
val gaeRuntimeZip by configurations.creating
299+
300+
dependencies {
301+
// 3. Declare the dependency on the App Engine runtime deployment zip
302+
gaeRuntimeZip("com.google.appengine:runtime-deployment:$gaeRuntimeVersion@zip")
303+
304+
// ... your other standard dependencies (e.g., implementation(...)) ...
305+
}
306+
307+
// 4. Configure the WAR task to unpack and rename the jars
308+
tasks.named<War>("war") {
309+
into("") {
310+
// Extract the contents of the zip file
311+
from(gaeRuntimeZip.map { zipTree(it) }) {
312+
// Flatten the directory structure
313+
eachFile {
314+
path = name
315+
}
316+
includeEmptyDirs = false
317+
}
318+
319+
// Strip the version number from the jar files
320+
rename { fileName: String ->
321+
fileName.replace("-$gaeRuntimeVersion", "")
322+
}
323+
}
324+
}
325+
```
326+
327+
### Groovy
328+
329+
```
330+
// 1. Define the target runtime version
331+
def gaeRuntimeVersion = "5.0.1-SNAPSHOT" // Change this to your desired version
332+
333+
// 2. Create a custom configuration for the runtime zip
334+
configurations {
335+
gaeRuntimeZip
336+
}
337+
338+
dependencies {
339+
// 3. Declare the dependency on the App Engine runtime deployment zip
340+
gaeRuntimeZip "com.google.appengine:runtime-deployment:${gaeRuntimeVersion}@zip"
341+
342+
// ... your other standard dependencies ...
343+
}
344+
345+
// 4. Configure the WAR task to unpack and rename the jars
346+
war {
347+
into('.') {
348+
// Extract the contents of the zip file
349+
from({ configurations.gaeRuntimeZip.collect { zipTree(it) } }) {
350+
// Flatten the directory structure just in case the zip has a root folder
351+
eachFile { file ->
352+
file.path = file.name
353+
}
354+
includeEmptyDirs = false
355+
}
356+
357+
// Strip the version number from the jar files
358+
// (e.g., 'runtime-main-5.0.1-SNAPSHOT.jar' becomes 'runtime-main.jar')
359+
rename { String fileName ->
360+
fileName.replace("-${gaeRuntimeVersion}", "")
361+
}
362+
}
363+
}
364+
```

0 commit comments

Comments
 (0)