GoogleCloudPlatform / gradle-appengine-plugin

Gradle plugin that provides tasks for uploading, running and managing Google App Engine projects
Apache License 2.0
236 stars 60 forks source link

appengineRun task looking in wrong directory for appengine-web.xml #287

Closed Robin-Hoodie closed 7 years ago

Robin-Hoodie commented 7 years ago

I've started an app engine standard project and tried to deploy an EAR file to the local development server using the appengineRun task.

I am using version 1.9.53

My basic directory structure looks like this:

The relevant code in my root build.gradle file looks like this:

buildscript {
  repositories {
    jcenter()
    mavenCentral()
  }
}

allprojects {
  group = 'be.robintron'
  version = '0-0-1'

  subprojects {
    apply plugin: 'java'
    sourceCompatibility = 1.7
    targetCompatibility = 1.7
  }

  repositories {
    maven {
      url 'https://maven-central.storage.googleapis.com'
    }
    jcenter()
    mavenCentral()
  }
}

My build.gradle file in the web folder:

apply plugin: 'war'

dependencies {
  providedCompile 'javax.servlet:servlet-api:2.5'
  compile "$appengineGroup:appengine:$appengineVersion"
}

My build.gradle file in the ear folder:

apply plugin: 'ear'
apply plugin: 'appengine'

buildscript {
  repositories {
    jcenter()
    mavenCentral()
  }

  dependencies {
    classpath "$appengineGroup:gradle-appengine-plugin:$appengineVersion"
  }
}

dependencies {
  deploy project(path: ':web', configuration: 'archives')
  appengineSdk "$appengineGroup:appengine-java-sdk:$appengineVersion"
}

appengine {
  downloadSdk = true

  appcfg {
    noCookies = false
    oauth2 = true
  }
  jvmFlags = ["-Ddatastore.backing_store=$projectDir/etc/appengineRun/local_db.bin", '-Xdebug',
              '-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000', '-Dappengine.fullscan.seconds=5']
  httpAddress = '0.0.0.0'
}

Finally, I added the appengine-web.xml file under web/src/main/webapp/WEB-INF and the application.xml file under ear/META-INF/application.xml. (Wasn't sure if application.xml is needed since the gradle-appengine-plugin seems to generate it)

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <!--Required but ignored, application.xml <application></application> tag is used-->
  <application>project-y</application>
  <service>default</service>
  <version>0-0-1</version>
  <threadsafe>true</threadsafe>
</appengine-web-app>
<?xml version="1.0"?>
<!-- This is the application.xml file intended for use with gradle, if you find it in your maven project, then that's a problem most likely. -->
<application xmlns="http://java.sun.com/xml/ns/javaee" version="6">
  <display-name>ear</display-name>
  <module>
    <web>
      <web-uri>web-0.1</web-uri>
      <context-root>web</context-root>
    </web>
  </module>
  <library-directory>lib</library-directory>
</application>

So far so good. However, upon running appengineRun I get following exception:

Caused by: com.google.apphosting.utils.config.AppEngineConfigException: Invalid appengine-web.xml(/home/robin/Development/project-y/ear/build/exploded-app/WEB-INF/appengine-web.xml) - Could not locate /home/robin/Development/project-y/ear/build/exploded-app/WEB-INF/appengine-web.xml

It's looking for appengine-web.xml under exploded-app instead of exploded-app/web-0-0-1/WEB-INF where the actual file resides. Any idea what I might've done wrong?

loosebazooka commented 7 years ago

If you're starting an appengine project from scratch, I would not use this plugin. Use the newer plugin based on gcloud : github.com/GoogleCloudPlatform/app-gradle-plugin. It has multimodule support that is not based on EARs (I wouldn't recommend EARs for multimodule projects)

Robin-Hoodie commented 7 years ago

@loosebazooka That's newer? I thought that was the older one :P Why would you not recommend EARS? How else would I build an appengine project with multiple services?

loosebazooka commented 7 years ago

There should be a deprecation notice on the README of this repository?

I think the older model with EARs was a nifty hack to mash the EAR model and the appengine model together. For running, the application-web.xml was just a descriptor to tell the server where all the modules were. For deployment, it would just deploy each one separately. It just involved a lot of extra set up to really not do anything.

The new model is just having separate gradle modules. Deployments can happen for each module as you update them, or running appengine:deploy on the root project will run the task on all subprojects. Running happens by referencing all the modules that you want to run together [see : multimodule-running]

Robin-Hoodie commented 7 years ago

@loosebazooka Thankyou for the detailed explanation, I'll set that up using the new plugin