Config: Eclipse Neon.1. BuildShip plugin 1.0.21. Gradle 3.2. Tomcat 8.0.33.
Project Structure:
CmbProduct
Common
CommonServer
Model
CaBridge
WebApp
I've got a Web Services application project ("WebApp") which is dependent on multiple other projects. When I use Eclipse WST/WTP to deploy and run WebApp via Tomcat, only Model.jar from "Model" is deployed into the tomcat WST runtime directory as:
.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapp/WEB-INF/lib/Model.jar
All other dependencies for hibernate, etc do seem to be deployed correctly to the same dir above.
This broke when I changed eclipse to use Buildship. Previously I used the Eclipse STS (Spring) plugin and that worked fine.
Here is the web project (WebApp) build.gradle:
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
dependencies {
compile project(":Common")
compile project(":Model")
compile project(":CommonServer")
compile project(":CaBridge")
...
}
eclipse {
wtp {
component {
// Configure the <Context path="..."/> in server.xml
contextPath = '/console'
// dependencies to mark as deployable with lib folder deploy path
libConfigurations += [ project(":MagniCompCommon").configurations.runtime ]
}
}
}
In the above example I first tried without the eclipse.wtp.libConfigurations section. I tried adding that to fix the problem but it has no effect. Yes, I did run 'gradle eclipseWtp', then Add/Remove the 'WebApp' application from its server entry after making that change.
If I go to Eclipse -> WebApp -> Properties -> Java Build Path -> Libraries and look at "Web App Libraries" I see "Model" but not the other projects. If I look at "Project and External Dependencies" I see all projects listed.
Here is the build.gradle for Model (working):
apply plugin: 'eclipse-wtp'
dependencies {
compile project(":MagniCompCommon")
}
Here is build.gradle for Common (not deployed):
apply plugin: 'eclipse-wtp'
dependencies {
//compile project(":MagniCompCommon")
compile project(":Model")
compile("org.glassfish.jersey.containers:jersey-container-servlet:$jerseyGlassfishVersion")
// Required for JAX-RS Client
compile("org.glassfish.jersey.core:jersey-client:$jerseyGlassfishVersion")
}
Here is build.gradle for the top level project (CmbProject):
apply plugin: 'java'
subprojects {
apply plugin: 'java'
apply plugin: 'nebula.provided-base'
apply plugin: 'nebula.optional-base'
sourceCompatibility = JavaVersion.VERSION_1_8
javadoc.enabled = false
sourceSets {
main {
java {
// Define all source dirs - Purpose is to add "src-gen"
srcDirs = ["src/main/java", "src-gen"]
}
}
}
/*
* Repositories used by each subproject must be given below.
* Because each subproject resolves dependencies of other
* subprojects, all subprojects must know all repos.
* In other words, if projectA needs repo "foo.org" and projectB
* depends upon projectA, then projectB needs repo "foo.org" as
* well.
*/
repositories {
maven {
// Local repo for annovention
url uri("$rootDir/MagniCompCommon/repo")
}
mavenCentral()
maven {
url "http://download.java.net/maven/2"
}
maven {
// Texo/EMF
url "https://oss.sonatype.org/content/groups/public/org/eclipse/emf"
}
maven {
// Eclipse
url "https://oss.sonatype.org/content/repositories/public/eclipse"
}
maven {
url "https://repository.jboss.org/nexus/content/groups/public-jboss"
}
maven {
url "http://maven.vaadin.com/vaadin-addons"
}
maven {
url "http://oss.sonatype.org/content/repositories/vaadin-snapshots"
}
maven {
url("http://maven.clapper.org")
}
/*
* -ADD LAST- so that it doesn' override any others
* DynamicReports depends upon JasperReports which lists their own
* bug fixed versions of packages like "com.lowagie:itext:2.1.7.js2"
* This repo provides such patched packages.
*/
maven {
url("http://jasperreports.sourceforge.net/maven2")
}
}
/*
* Variables local to this file
*/
def bouncycastleVersion = "1.54" // Was 1.51
def slf4jVersion = "1.7.19"
def hibernateVersion = "4.3.11.Final"
def texoVersion = "0.9.0-v201501182340"
def emfVersion = "2.11.0-v20150123-0347"
def jnaVersion = "4.1.0"
ext {
/*
* Variables here are used by subprojects
*/
vaadinVersion = "7.6.8" // was 7.6.4
vaadinIconsVersion = "1.0.1"
jerseyGlassfishVersion = "2.23.2" // was 2.22.2
}
dependencies {
/*
* PRODUCT SPECIFIC
*/
compile("org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion")
compile("org.bouncycastle:bcprov-ext-jdk15on:$bouncycastleVersion")
compile("org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion")
compile("com.h2database:h2:1.3.176")
testCompile("org.testng:testng:6.9.4")
/*
* MagniComp common and product
*/
compile("org.simpleframework:simple-xml:2.6.9")
// Logging slf4j API
compile("org.slf4j:slf4j-api:$slf4jVersion")
// Send JCL to slf4j
compile("org.slf4j:jcl-over-slf4j:$slf4jVersion")
// Anything using JUL should defer to slf4j
compile("org.slf4j:jul-to-slf4j:$slf4jVersion")
// Send slf4j to log4j 1.2 for those JARs which use slf4j
compile("org.slf4j:slf4j-log4j12:$slf4jVersion")
// Log4j itself
compile("log4j:log4j:1.2.17")
// Hibernate
// Do not include "hibernate-core" explicitly as hibernate-entitymanager will take care of it
compile("org.hibernate:hibernate-entitymanager:$hibernateVersion")
compile("org.hibernate:hibernate-c3p0:$hibernateVersion")
compile("mysql:mysql-connector-java:5.1.38")
// Texo
compile("org.eclipse.emf:org.eclipse.emf.texo:$texoVersion")
compile("org.eclipse.emf:org.eclipse.emf.texo.server:$texoVersion")
compile("org.eclipse.emf:org.eclipse.emf.texo.xml:$texoVersion")
// Texo dependencies (not automaticly added by texo)
compile("org.eclipse.emf:org.eclipse.emf.common:$emfVersion")
compile("org.eclipse.emf:org.eclipse.emf.ecore:$emfVersion")
compile("org.eclipse.emf:org.eclipse.emf.ecore.xmi:$emfVersion")
// Required by org.eclipse.emf
// Disable because it's causing:
// java.lang.SecurityException: class "org.osgi.framework.BundleReference"'s signer information does not match signer information of other classes in the same package
//compile("org.eclipse.core:org.eclipse.core.runtime:3.7.0")
compile("org.jsoup:jsoup:1.7.2")
// Apache HTTP client
compile("org.apache.httpcomponents:httpclient:4.3.5")
// EventBus and more
compile("com.google.guava:guava:18.0")
// Quartz scheduler
compile("org.quartz-scheduler:quartz:2.2.2") {
exclude group: "c3p0", module: "c3p0"
}
// Java Mail
compile("javax.mail:mail:1.4.5")
// JNA for Common and CaBridge
compile("net.java.dev.jna:jna:$jnaVersion")
compile("net.java.dev.jna:jna-platform:$jnaVersion")
// This package provided by Tomcat or Servlet container
provided("javax.servlet:javax.servlet-api:3.1.0")
}
}
Thanks to some help from the gradle forum I found the solution.
Each project which is a dependency of a WTP project must each have:
apply plugin: 'eclipse-wtp'
Having this only in the WTP project is not enough.
Related
We are looking to migrate from Maven to Gradle, and have worked through most of the challenges you would expect for replacing the parent POM concept. There is one sticky point that we haven't figured out yet. We need to specify the version of Spring Boot we are using globally, but I run into invalid build file problems with both of the solutions I've tried:
I tried putting the plugins { id 'org.springframework.boot' version '2.1.17.RELEASE' } declaration in the common build script. Build error, "Only Project and Settings build scripts can contain plugins {} blocks."
I tried calling the common build file to specify the springBootVersion parameter and using that in the plugins declaration. Build Error, "only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed"
All of this would be easier if I could simply apply plugin: 'org.springframework.boot' but then Gradle can't find the plugin. All but one microservice are on a single version of Spring Boot, and we want to be able to upgrade globally if possible.
Additional Information
I have ~40 microservices plus some libraries used by those services
Separate repository for each of them, so the normal parent/child approach does not work
Maven parent POMs allowed you to publish that POM as it's own resource, and there is no 1:1 equivalent feature in Gradle
Gradle pluginManagement concept also doesn't work for us because it resolves the Spring Boot plugin but the dependency management plugin now can't be found.
My common build script is included here:
repositories {
mavenLocal()
/* Removed our internal repositories */
jcenter()
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'maven-publish'
apply plugin: 'io.spring.dependency-management'
group = 'nedl-unified-platform'
/* Required to publish Spring Boot microservices to publish to repository */
configurations {
[apiElements, runtimeElements].each {
it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
it.outgoing.artifact(bootJar)
}
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
withJavadocJar()
withSourcesJar()
}
ext {
set('springBootVersion', '2.1.17.RELEASE')
set('springCloudVersion', "Greenwich.SR6")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
jacoco {
toolVersion = "0.8.5"
reportsDir = file("$buildDir/reports/jacoco")
}
test {
finalizedBy jacocoTestReport // report is always generated after tests run
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.2
}
}
}
}
jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.enabled true
html.destination file("${reportsDir}/jacocoHtml")
xml.destination file("${reportsDir}/jacocoReport.xml")
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
repositories {
/* excluded for privacy and brevity's sake, our internal Maven repo */
}
}
And that is called by our project build script that I want to parameterize:
plugins {
id 'org.springframework.boot' version springBootVersion
}
apply from: "https://mycentral.repo/project-common/develop/build.gradle"
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
implementation 'ch.qos.logback:logback-classic'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'
implementation 'org.glassfish.jaxb:jaxb-runtime:2.4.0-b180830.0438'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
version = '0.0.2-SNAPSHOT'
I think the gap here is that in maven you have the concept of a parent pom, whereas in Gradle you don't. There is no 1:1 mapping to this like you say, but you can have plugins in Gradle, and apply a plugin.
The closest thing you would have is if you developed your own Gradle plugin, which each of your projects could apply. Your custom plugin would then configure Spring Boot among whatever else is common to all your projects. This plugin would define the version of Spring Boot you want all your other projects to use.
You wouldn't get much benefit to a custom plugin if it's only concern is configuring Spring Boot, it would need to do other things as well. It can be difficult to create a Gradle plugin when you don't have allot of experience in it. You lose all the familiar syntax to the build.gradle and you literally have to write code, (there are some similarities but I have found it difficult), I would avoid it if possible.
I would suggest you start off by applying the spring boot plugin directly to one of your microservices projects, get that working, then do another. After you have done a number of them you will then be able to see what is common between them, and if it is indeed worth investing into developing a global plugin. You really need to be careful though because your global plugin has the potential to be both a blessing and curse. It may take away allot of manual work for maintainers, but if you get it wrong it will cause them grief, and then they will want to go back to maven.
I'm not sure if I understand your globally defined Spring version requirement. Unless you are using SNAPSHOT dependencies/plugins (bad don't do that), (or a black magic settings.gralde outside of your repo), you will have to put some version somewhere. As an alternative you could create your own custom task which runs on the check lifecycle which will check the version of spring (or your plugin) and print a warning if it's not the latest version, and encourage the developer to upgrade.
Extra Info
Parameterizing plugins with properties can be done putting your property in gradle.properties as springBootVersion=2.1.17.RELEASE .
I'm not sure I understood your issue perfectly but you should use the Gradle way for sharing configuration : the root project config.
Instead of including the common build script in every project, create a global project and set the configuration here.
root
|
| --- projectA
| --- projectB
| --- projectC
With the according settings.gradle
include 'projectA'
include 'projectB'
include 'projectC'
In the root build.gradle, set up the version
ext.springBootVersion = '2.1.17.RELEASE'
In subprojects using springBoot, let's say projectB, apply the plugin in the sub build.gradle
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
}
}
apply plugin: 'org.springframework.boot'
This example works for me, though I may not understand all of the constraints.
If we abstract the version of Spring Boot behind a fixed URI (e.g. on an internal CI/CD server), then consider this in each project/repo's build.gradle:
buildscript {
repositories {
jcenter()
}
def SPRING_BOOT_VERSION_URI = 'http://localhost:5151/api-server/spring-boot.txt'
ext.springBootVersion = new URL(SPRING_BOOT_VERSION_URI).getText().trim()
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
}
}
apply plugin: 'org.springframework.boot'
apply from: "../common/build.gradle"
I realize the original question states that the apply plugin doesn't work, but it's not clear to me if that precludes this method.
Finally, note that it is easy to expand this beyond a simple text-file to be a more formal JSON specification (tailored to the teams' needs).
If you add this to the root project, all child projects should be able to just import from the same set of Spring Boot dependencies. The magic ingredient is the allprojects block:
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
ext {
springBootVersion = '2.3.4.RELEASE'
}
allprojects {
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
}
}
}
apply plugin: 'org.springframework.boot'
After cleaning when i try to build gradle i get an error in the console saying:
package org.json does not exist import org.json.JSONObject;
cannot find symbol
symbol : class JSONObject
there are red marks in the java file at all places where jsonobject and json array exists.
I have put the folder web inf/lib that contains all the jar files inside the src/main/webapp directory that i have created.
currently the contents of my build.gradle file are:
/*
* This build file was auto generated by running the Gradle 'init' task
* by 'i2cdev001' at '14/11/18 3:11 PM' with Gradle 2.14.1
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/2.14.1/userguide/tutorial_java_projects.html
*/
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'war'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.21'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}
Note: Also in the project properties i am unable to see any jar files under the Web App Libraries in the java build path tab. I can see only access rules:no rules defined and native library locations:(none)
As your project is gradle project, Adding jar manually wont work.. You have to mention path where you have kept all your jar files in your build.gradle file.
Mention your jar file path in repository under flatDir {}:
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
Then you have to add which jar from that folder you have mentioned above (ie libs)
dependencies {
compile 'gson-0.1.0'
}
I am learning Spring MVC and trying to use it together with Gradle and Gretty plugin. I have successfully created a "Hello World" project, however I am not able to use hot deployment with Gretty, despite setting the managedClassReload=true. I run the application by using appRun gretty task from IntelliJ. My build.gradle is as follows:
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'war'
apply from: 'https://raw.github.com/gretty-gradle-plugin/gretty/master/pluginScripts/gretty.plugin'
group = 'lukeg'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
mainClassName = 'lukeg.LearnApplication'
repositories {
mavenCentral()
maven {
url 'https://repo.spring.io/libs-snapshot'
}
}
dependencies {
compileOnly('org.projectlombok:lombok:+')
compile('org.springframework:spring-webmvc:4.3.17.RELEASE')
compile("org.aspectj:aspectjweaver:1.8.11")
compile('org.springframework:spring-context:4.3.18.BUILD-SNAPSHOT')
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
}
gretty {
httpPort = 8080
contextPath = '/'
servletContainer = 'tomcat9'
//reloadOnClassChange=true
managedClassReload=true
loggingLevel='DEBUG'
}
It does not matter whether I use tomcat9 or jetty9 for servlet container: the logs do not show that the changes to source files in project are detected by Gretty.
Interesingly enough, when I comment out the managedClassReload=true line and uncomment reloadOnClassChange=true the changes to source files are detected and the project is automatically reloaded.
What can be the cause for gretty's hot deployment not working? Does springloaded not work together with Spring MVC?
First of all, there is no need to depend on the plugin script you are gathering from github since org.gretty is available in the official Gradle plugin repository for some time already:
plugins {
id "org.gretty" version "2.1.0"
}
Since you are running your app inplace using appRun, your changes will not be reloaded.
You have to run you application as war, using appRunWar.
This is not mentioned in the documentation. But in the Gretty source code.
You can check the Gretty code which causing your issue in the BaseScannerManager:
if(wconfig.reloadOnClassChange)
{
if(managedClassReload)
{
if(wconfig.inplace) // <-- your problem, you are running inplace
{
log.info 'file {} is in managed output of {}, servlet-container will not be restarted', f, wconfig.projectPath
}
else
{
log.info 'file {} is in output of {}, but it runs as WAR, servlet-container will be restarted', f, wconfig.projectPath
webAppConfigsToRestart.add(wconfig)
}
}
else
{
log.info 'file {} is in output of {}, servlet-container will be restarted', f, wconfig.projectPath
webAppConfigsToRestart.add(wconfig)
}
}
I'm working with a Gradle project in Eclipse Oxygen with Java 8 and Gradle wrapper 4.6.
When i tried to add a new dependency compile 'com.googlecode.json-simple:json-simple:1.1.1' and refresh the project, all the "Project and External Dependencies" folder disappeared without a trace, which stops my project running from Eclipse (it can run through Gradle Run task though).
Removing the newly added dependency does not save me. Neither gradlew cleanEclipse & gradlew eclipse nor refreshing the project countless times.
I also attempted to clear the cache and forced project to rebuild when reimport, but no "Project and External Dependencies" shows up.
What should i do to bring back the old dependencies?
Here is my build.gradle
// Apply the java plugin to add support for Java
apply plugin: 'java'
// Apply the plugin to be runnable
apply plugin: 'application'
// Apply the eclipse plugin to import project on other machines
apply plugin: 'eclipse'
// JUnit 5
apply plugin: 'org.junit.platform.gradle.plugin'
// Define the entry point
mainClassName = 'meshIneBits.MeshIneBitsMain'
applicationName = 'MeshIneBits'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
sourceCompatibility = 1.8
// In this section you declare the dependencies for your production and test code
dependencies {
compile 'org.processing:core:3.3.5'
compile 'org.jogamp.jogl:jogl-all:2.3.2'
compile 'org.jogamp.gluegen:gluegen-rt:2.3.2'
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-amd64"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-armv6"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-armv6hf"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-i586"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-macosx-universal"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-windows-amd64"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-windows-i586"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-amd64"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-armv6"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-armv6hf"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-i586"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-macosx-universal"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-solaris-i586"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-windows-amd64"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-windows-i586"
testCompile('org.junit.jupiter:junit-jupiter-api:5.1.0',
'org.junit.jupiter:junit-jupiter-params:5.1.0')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.1.0',
'org.junit.platform:junit-platform-launcher:1.1.0')
}
eclipse {
project.natures 'org.eclipse.buildship.core.gradleprojectnature'
classpath {
file {
defaultOutputDir = file('bin/main')
whenMerged {
//change output folder for tests
def testsrc = entries.find { it.path == 'src/test/java' }
testsrc.output = "bin/test"
def testres = entries.find { it.path == 'src/test/resources' }
testres.output = "bin/test"
// Remove local ref for libs
entries.removeAll{ it.kind == "lib" }
}
containers 'org.eclipse.jdt.junit.JUNIT_CONTAINER/5', 'org.eclipse.buildship.core.gradleclasspathcontainer' }
}
}
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'org.junit.platform:junit-platform-gradle-plugin:1.1.0' }
}
jar {
baseName = applicationName
version = '0.2.0'
manifest { attributes 'Main-Class' : mainClassName }
}
Edit:
After switching to IntelliJ, the problem is solved (i used the same folder of project). So i think this is a problem in Eclipse.
I also had this problem where the "Project and External Dependencies" folder disappeared. It instead showed as 'org.eclipse.buildship.core.gradleclasspathcontainer'.
If you do not see that line, then it needs to be added to the .classpath file.
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer" />
The fix that worked for me was closing Eclipse, and running
gradlew cleanEclipse eclipse
then opening Eclipse and adding the Gradle nature to the project.
I also encountered this problem when I refactor the project name.
Following steps solve my problem:
add eclipse plugin to build.gradle
right click build.gradle, choose gradle then select refresh gradle project
only refresh gradle project didn't help me.
I'm really confused about converting an old Google App Engine project to Gradle.
I'm trying to follow the instructions on this page. It advises to start with this build script:
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:+' // latest App Engine Gradle tasks
}
}
repositories { // repositories for Jar's you access in your code
maven {
url 'https://maven-central.storage.googleapis.com' // Google's mirror of Maven Central
// url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT Repository (if needed)
}
jcenter()
mavenCentral()
}
apply plugin: 'java' // standard Java tasks
apply plugin: 'war' // standard Web Archive plugin
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
dependencies {
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
compile 'com.google.appengine:appengine:+'
// Add your dependencies here.
}
appengine { // App Engine tasks configuration
run { // local (dev_appserver) configuration (standard environments only)
port = 8080 // default
}
deploy { // deploy configuration
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
}
group = 'com.example.appengine' // Generated output GroupId
version = '1.0-SNAPSHOT' // Version in generated output
sourceCompatibility = 1.7 // App Engine Standard uses Java 7
targetCompatibility = 1.7 // App Engine Standard uses Java 7
However it doesn't work:
$ gradle appengineRun
FAILURE: Build failed with an exception.
* Where:
Build file '/path/to/myproject/build.gradle' line: 32
* What went wrong:
A problem occurred evaluating root project 'myproject'.
> Could not find method run() for arguments [build_c1i62diotjttavcmtjg1zqlbd$_run_closure3$_closure5#33f17289] on root project 'myproject' of type org.gradle.api.Project.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Shouldn't the dependencies be downloaded to make the custom appengine task configuration work?
Please have a look at the sources of the plugin. When the core plugin is applied it decides whether to apply a flexible or standard appengine plugin. Since there's probably no src/main/webapp/WEB-INF/appengine-web.xml flexible plugin is applied which does not create the extension that fails (FYI, this extension is created here). To fix the problem run:
mkdir -p src/main/webapp/WEB-INF
and then:
touch src/main/webapp/WEB-INF/appengine-web.xml
in console where build.gradle is located. This will solve the problem. Poor documentation :/