Migrating from Google Cloud Tools in Eclipse, Google App Engine Java Project to Gradle

79 Views Asked by At

Google Cloud Tools for Eclipse is going to become obsolete January 30, 2024 due to its lack of support of Java 11+ and Java 8 will become undeployable. Because of that I am trying to convert from my Eclipse Standard Java App Engine project to using a gradle build file and gcloud app deploy. I added a gradle.build file to the root of the java project that look like this:

buildscript {      // Configuration for building
  repositories {
    jcenter()      // Bintray's repository - a fast Maven Central mirror & more
    mavenCentral()
  } 

   dependencies {
    classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.5.0'
   }

}

repositories {   // repositories for Jar's you access in your code
  jcenter()
  mavenCentral()
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.google.cloud.tools.appengine'

dependencies {
  providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
  providedCompile 'com.google.appengine:appengine:+'
// Add your dependencies here.

}

  appengine {
    deploy {   // deploy configuration
      stopPreviousVersion = true  // default - stop the current version
      promote = true              // default - & make this the current version
    }
  }


sourceCompatibility = 11
targetCompatibility = 11

I took this directly from Google's example and remove the gretty and jetty libraries from it, because whenever I tried to build using gradle I would get the error: Could not set unknown property 'baseName' for task ':archiveProduct' of type org.gradle.api.tasks.bundling.Zip. I think those libraries are just for running the app locally, so I don't think it's a big deal that I removed them, but let me know if it is.

I also added an app.yaml file that looks like this:

runtime: java11
service: serviceName
entrypoint: java -cp "*" packagename.Driver

When I was trying to deploy my code the gcloud app deploy command was complaining about a lack of a Main Class so I added one to the project even though I don't think it needs one, because it was working just fine without it on Eclipse. It looks like this:

package packageName;

public class Driver {
    public static void main(String[] args) {
        System.out.println("This is a driver main class.");
    }
}

When I deployed it my appengine just give the error Service Unavailable and none of my servlets that were mapped with web.xml work.

I am not sure why google won't just add support for Java 11+ to Google Cloud Tools for Eclipse, but because of that I have to deal with this.

If Someone has any idea how to take a standard java appengine project from Eclipse and deploy it using gradle that would be great.

1

There are 1 best solutions below

1
On

I figured it out, you have to restructure the folder structure like in the following:

your-app-engine-project/
│
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── com/
│   │   │       └── example/
│   │   │           └── YourApp.java
│   │   ├── appengine/
│   │   │   ── app.yaml
│   │   └── webapp/
│   │       ├── WEB-INF/
│   │       │   └── appengine-web.xml
│   │       └── index.jsp
├── build.gradle

and I changed my app.yaml file to have the following entrypoint instead of my main class entrypoint: java -noverify -jar 'nameofwarfilefrombuild'.war

Put all the war folder files from your eclipse project inside src/main/webapp and all your java code file under src/main/java

Deploy the app using ./gradlew appengineDeploy or gradle appengineDeploy.