Skip to content

Commit 8d977ed

Browse files
suztomompeddada1
andauthored
feat(appengine): Gradle on java21 helloworld (GoogleCloudPlatform#9499)
* chore: expperiment with using jdk 21 for appengine sample * feat: add appengine maven sample for jdk 21 * fix copyright * update maven-plugin version * modify pom.xml and remove index.jsp * remove project id * update shared-configurations * restore pom * restore appengine8 to main * Gradle 8 wrapper * test dir * Last Gretty * Gretty 4.1.5 (latest) * use the Gradle plugin * restoring java8 file * Gradle wrapper installed * Google header * updating appengine library versions --------- Co-authored-by: mpeddada1 <mpeddada@google.com>
1 parent 5774b89 commit 8d977ed

7 files changed

Lines changed: 469 additions & 2 deletions

File tree

appengine-java21/helloworld/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,25 @@ To use vist: http://localhost:8080/
5757

5858
To use vist: https://YOUR-PROJECT-ID.appspot.com
5959

60-
## Testing
60+
### Testing
6161

6262
mvn verify
6363

64-
6564
As you add / modify the source code (`src/main/java/...`) it's very useful to add [unit testing](https://cloud.google.com/appengine/docs/java/tools/localunittesting)
6665
to (`src/main/test/...`). The following resources are quite useful:
6766

6867
* [Junit4](http://junit.org/junit4/)
6968
* [Mockito](http://mockito.org/)
7069
* [Truth](http://google.github.io/truth/)
70+
71+
## Gradle
72+
73+
### Running locally
74+
75+
./gradlew appengineRun
76+
77+
To use vist: http://localhost:8080/
78+
79+
### Deploying
80+
81+
./gradlew appengineDeploy
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
apply plugin: 'java'
18+
apply plugin: 'war'
19+
20+
buildscript {
21+
repositories {
22+
// gretty plugin is in Maven Central
23+
mavenCentral()
24+
}
25+
dependencies {
26+
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.8.1'
27+
classpath 'org.gretty:gretty:4.1.5'
28+
}
29+
}
30+
apply plugin: 'org.gretty'
31+
apply plugin: 'com.google.cloud.tools.appengine'
32+
33+
repositories {
34+
mavenCentral()
35+
}
36+
37+
appengine {
38+
deploy { // deploy configuration
39+
stopPreviousVersion = true // default - stop the current version
40+
promote = true // default - & make this the current version
41+
projectId = 'GCLOUD_CONFIG'
42+
version = 'GCLOUD_CONFIG'
43+
}
44+
}
45+
46+
sourceSets {
47+
// In Gradle 8, the default location is app/src/java, which does not match
48+
// Maven's directory structure.
49+
main.java.srcDirs = ['src/main/java']
50+
main.resources.srcDirs = ['src/main/resources', 'src/main/webapp']
51+
test.java.srcDirs = ['src/test/java']
52+
}
53+
54+
dependencies {
55+
implementation 'com.google.appengine:appengine-api-1.0-sdk:2.0.30'
56+
implementation 'jakarta.servlet:jakarta.servlet-api:6.1.0'
57+
58+
// Test Dependencies
59+
testImplementation 'com.google.appengine:appengine-testing:2.0.30'
60+
testImplementation 'com.google.appengine:appengine-api-stubs:2.0.30'
61+
testImplementation 'com.google.appengine:appengine-tools-sdk:2.0.30'
62+
63+
testImplementation 'com.google.truth:truth:1.1.5'
64+
testImplementation 'junit:junit:4.13.2'
65+
testImplementation 'org.mockito:mockito-core:4.11.0'
66+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file was generated by the Gradle 'init' task.
2+
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
3+
4+
[versions]
5+
guava = "33.2.1-jre"
6+
junit = "4.13.2"
7+
8+
[libraries]
9+
guava = { module = "com.google.guava:guava", version.ref = "guava" }
10+
junit = { module = "junit:junit", version.ref = "junit" }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

appengine-java21/helloworld/gradlew

Lines changed: 252 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)