how to create Google App Engine Project with Gradle - java

A I'm new to Google App Engine and even I have Spring tool suite with gradle plugin installed, I facing difficulty . I want to know what the process ,how to implement ,if any sample basic project to implement can anybody help me .Even I have Goggled but getting get the doc and but when I'm trying to implement getting errors,unable to create a sample project any suggestion with code is appreciated
Thanks in advance....

Here is my setup for the appengine guestbook sample
https://developers.google.com/appengine/docs/java/gettingstarted/introduction
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.4'
}
}
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = 1.7
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.4'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
appengine {
httpPort = 8085
appcfg {
email = 'you#gmail.com'
passIn = true
logs {
severity = 1
outputFile = file('mylogs.txt')
}
app {
id = 'guestbook'
}
}
}
gradle.properties (in project root)
systemProp.appengine.sdk.root = /Users/<me>/Documents/appengine-java-sdk-1.9.4
Create a webapp directory in your project's "src/main" folder and copy the files from the sample webapp directory there.

I'd check out the docs for Google's offical Gradle AppEngine plugin, which also has a small example. SpringSource Tool Suite is irrelevant here. If you hit any problems, post a concrete question that explains the problem in detail, along with all output you get.

Related

Firestore credentials problem: Firebase app [default] already exists

I'm building a simple program in JavaFX for uploading .xls files to my firebase/firestore project. Everytime I try to run the program and click on a button to init my uploader class, it fails with an error message:
FirebaseApp name [DEFAULT] already exists!
After searching for a long time, I have yet to find something useful. I've tried OAuth2 tokens (created a service account in Google Cloud, got the JSON file), environment variables (won't detect), pretty much everything in docs.
FileInputStream serviceAccount = new FileInputStream("<path>.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://<project>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options); <----This line won't compile for some reason..
Firebase app =FirebaseApp.initializeApp(options); <--------- This will compile
I'm using Gradle for my building tool. This is what I've got so far and it seems to build nicely without problems. Am I missing any dependencies?
plugins {
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'application'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile "org.apache.poi:poi:3.17"
compile "org.apache.poi:poi-ooxml:3.17"
implementation 'com.google.firebase:firebase-auth:18.1.0'
implementation 'com.google.firebase:firebase-admin:6.9.0'
implementation 'com.google.firebase:firebase-firestore:20.2.0'
compile 'com.google.firebase:firebase-admin:6.9.0'
}
javafx {
version = '12'
modules = ['javafx.controls', 'javafx.fxml']
}
mainClassName = 'app.Main'
apply plugin: 'org.openjfx.javafxplugin'
You can't use firebase-admin alongside other Firebase Android libraries like firebase-auth and firebase-firestore. You should either use the Admin SDK or the Android SDK, but never both.
Coming to the exact error message, it's an indication that initializeApp() is getting called multiple times in your app. It's trying to initialize the [DEFAULT], when one already exists.

Swagger Gradle Plugin not properly generating openapi.json file for spring mvc during build

I would like to import API definition files created with the swagger gradle plugin. I have a spring boot mvc app. I don't seem to be able to get the resolve settings correct to generate the openAPI.json. The gradle resolve task creates an empty file with just the "openapi" : "3.0.1" tag and value. The resolve task is not picking up the swagger and mvc api annotations. Can you point me in the right direction to find the right configuration settings for the swagger gradle resolve task?
The application displays the Spring-UI documentation without a problem when the app is running and I view the swagger-ui endpoint. The issue is during the gradle build there is a separate gradle task to generate the openAPI.json file that I would like to import into SwaggerHub as part of the application API catalog.
I have been unable to find any documentation anywhere on how to configure the swagger gradle plugin resolve task to pick up the Spring MVC API annotations. I can get it to work fine on another application that uses the jax-rs annotations so I am certain that it is a resolve task configuration issue.
A copy of my gradle.build file:
buildscript {
ext {
springBootVersion = '1.4.1.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.6.RELEASE")
// SwaggerHub Plugin Dependency
classpath("gradle.plugin.io.swagger:swaggerhub:1.0.1")
// Swagger Gradle Plugin Dependency
classpath("io.swagger.core.v3:swagger-gradle-plugin:2.0.5")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco'
// Required to upload swagger api doc to swaggerhub
apply plugin: 'io.swagger.swaggerhub'
// Required to generate swagger api doc file to upload to swaggerhub
apply plugin: 'io.swagger.core.v3.swagger-gradle-plugin'
jar {
baseName = 'service-framework'
version = '0.0.1-SNAPSHOT'
}
javadoc {
source = sourceSets.main.allJava
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-web')
// Swagger Dependencies to generate the api documentation
compile('io.swagger:swagger-annotations:1.5.20')
compile('io.springfox:springfox-swagger2:2.8.0')
compile('io.springfox:springfox-swagger-ui:2.8.0')
runtime('com.h2database:h2')
runtime('org.postgresql:postgresql')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3'
testCompile group: 'junit', name: 'junit-dep', version: '4.10'
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
}
// Command to the swagger gradle plugin to generate the api file for upload
// to swaggerhub
//
//
// Create the directory for output of the api document
File path = new File("${buildDir}/doc")
//
// The Swagger Core Task to create the json output file required to upload
// to SwaggerHub
//
resolve {
outputFileName = 'openAPI'
outputFormat = 'JSON'
prettyPrint = 'TRUE'
classpath = sourceSets.main.runtimeClasspath
resourcePackages = ['test.serviceframework']
outputPath = path.getAbsolutePath();
}
The resulting output in the openAPI.json file:
{
"openapi" : "3.0.1"
}
I know this is an old question but since the original post, the Swagger gradle plugin hasn't resoved this issue. However, Spring Doc has.
https://github.com/springdoc/springdoc-openapi-gradle-plugin
There doesn't yet seem to be an auto-documentation tool for Spring (MVC/Rest) and OpenAPI 3.
SpringFox does this for Swagger 2. Looks like you've got this added, so you should see your Swagger 2 Doc at /v2/api-docs
io.swagger.core does OpenAPI 3 for JAX-RS and Jersey
Options at this point are:
Generate Swagger 2, and convert it to OpenAPI 3
Run JAX-RS inside Spring

clone git repository on my gradle using Grgit

I have a gradle project which runs a script, and somewhere in it, I need to clone a git repository.
I had it running before with svn, but I change our company SCM to gitlab, and I need to change the code so it'll now clone the repo from git.
I need something that will work similar to this SVN code:
task exportLibs(type: SvnExport) {
svnUrl = "http://<svn-url>"
targetDir = "<target-dir-to-download-files>"
}
So I read about Grgit, but there was not a single example online, how to do a simple git clone (only this link http://ajoberstar.org/grgit/docs/groovydoc/org/ajoberstar/grgit/operation/CloneOp.html). If there is someone who can help me walkthrough this problem or maybe produced me to his grgit project so i will learn from it, it'll be awesome!
--Edit--
when i tried to use the grgit as below:
group 'test'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.ajoberstar:gradle-git:1.7.2"
}
}
apply plugin: 'java'
apply plugin: 'org.ajoberstar.grgit'
org.ajoberstar.grgit.auth.hardcoded.allow=true
task pullFromGit{
doLast {
//grgit.pull()
}
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
i've use this properties to initial it, and i got the following error:
A problem occurred evaluating root project 'grgit'.
Could not get unknown property 'org' for root project 'grgit' of type org.gradle.api.Project.
There is a link on the github page of the project to some examples and the API documentation. The following snippet would solve your problem (in this case, it will clone the grgit project to the grgit directory)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.ajoberstar:grgit:1.7.2'
}
}
task hello {
doLast {
org.ajoberstar.grgit.Grgit.clone(dir: 'grgit', uri: 'https://github.com/ajoberstar/grgit.git')
}
}
Answer to the edited question
The documentation states that org.ajoberstar.grgit.auth.hardcoded.allow is a system property. Your assignment is not a valid way to set system properties, see the answer to this question for examples on setting system properties in groovy.
my code probably had some special imports in it, cause a the end the only clone that i could have done is shell exec.
the problem is solved, but not the bug i had...

Cannot import when using Eclipse and Gradle

I am working on a java project which uses Gradle to build. I wanted to use the Eclipse WindowBuilder to help with the GUI work, so I used the Gradle Eclipse plugin, generated the Eclipse files, and imported it into Eclipse.
The problem is that none of my imports are resolving. The project builds fine using Gradle, but Eclipse can't import anything for my project. How do I solve this?
I don't know which files to include to help debug this, so if something might help let me know and I will include it.
Thanks in advance for your help!
EDIT: Here is my build.gradle file:
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
buildscript {
def rosMavenPath = "$System.env.ROS_MAVEN_PATH".split(':').collect { 'file://' + it }
def rosMavenRepository = "$System.env.ROS_MAVEN_REPOSITORY"
repositories {
rosMavenPath.each { p ->
maven {
url p
}
}
mavenLocal()
maven {
url rosMavenRepository
}
}
dependencies {
classpath group: 'org.ros.rosjava_bootstrap', name: 'gradle_plugins', version: '[0.1,0.2)'
}
}
apply plugin: 'catkin'
apply plugin: 'eclipse'
allprojects {
/*
A github url provides a good standard unique name for your project
Example below, but you may wish to switch to your own unique url.
*/
group 'com.github.rosjava.gui_test'
version = project.catkin.pkg.version
}
subprojects {
/*
See https://github.com/rosjava/rosjava_bootstrap (look for gradle_plugins)
to see what is going on under the hood.
*/
apply plugin: 'ros-java'
}

Gradle with IntelliJ not loading PostgreSQL JDBC as a dependency

I am trying to setup IntelliJ alongwith Gradle and JOOQ for my next project. As of now, this is how my Gradle file looks like:
apply plugin: 'java'
apply plugin: 'jooq'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
dependencies {
compile 'org.jooq:jooq:3.1.0'
compile 'com.google.guava:guava:14.0'
compile 'postgresql:postgresql:9.1-901-1.jdbc4'
}
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'postgresql:postgresql:9.1-901-1.jdbc4'
classpath 'com.github.ben-manes:gradle-jooq-plugin:0.5'
}
}
jooq {
... snip ...
}
And this is how my external dependencies (in IntelliJ) show up:
.
Somehow, Gradle is downloading and IntelliJ is recognizing the jooq and guava as part of my dependencies, but postgresql does not show up. So, while doing this works (using Guava, a dependency loaded from Gradle):
List<String> stringList = Lists.newArrayList();
This fails with a ClassNotFoundException:
Class.forName("org.postgresql.Driver").newInstance();
While doing a ./gradlew build, I have seen gradle output the fact that it did download thr postgresql-9.1-901 jar from Maven Central, but I don't know where it keeps it. Any help is greatly appreciated.
Apparently, I really need to RTFM. I hadn't refreshed the dependencies from the Gradle tool window in IntelliJ after making changes to the Gradle script. Got it from here: https://www.jetbrains.com/idea/webhelp/synchronizing-changes-in-gradle-project-and-intellij-idea-project.html

Categories

Resources