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.
Related
I'm following a tutorial on publishing artifacts to Nexus and a simple Java app is used as an example. A Gradle file is provided and meant to be changed. In the end, it looks like this:
plugins {
id 'java'
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
}
group 'com.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
artifacts("build/libs/my-app-$version"+".jar") {
extension = 'jar'
}
}
}
repositories {
maven {
name'nexus'
url "http://someip:someport/repository/maven-snapshots/"
credentials {
username project.repoUser
password project.repoPassword
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '5.2'
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
I when I use the command ./gradle build I get the following error:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/matteo/Desktop/devops_bootcamp/java-app/build.gradle' line: 14
* What went wrong:
A problem occurred evaluating root project 'my-app'.
> No signature of method: build_49q3y83g7hdxe5s51k5187z33.publishing() is applicable for argument types: (build_49q3y83g7hdxe5s51k5187z33$_run_closure1) values: [build_49q3y83g7hdxe5s51k5187z33$_run_closure1#79692f52]
Gradle version: Gradle 7.4.2
What am I doing wrong?
The "no signature of method" problem is a bug that happens when a closure can't compile. It should be fixed in the upcoming Gradle version 7.5.
The reason that it can't compile is because artifacts is a property and extension is a method (you have them both the other way around). There is also a method called artifact (in singular) that you probably want to use.
It is difficult to just guess what syntax to use, so check the documentation on it here.
There are various ways you can express this publication, but one is like the snippet below.
publications {
maven(MavenPublication) {
artifact("build/libs/my-app-$version"+".jar") {
extension('jar')
}
}
}
I'm new to Gradle and I'm working on a Liferay project. I'm trying to use the Liferay javadoc gradle plugin without success. I'm working on the Liferay IDE (Eclipse) and I already have the javadoc task available to execute. The problem is, after the excution (which completes successfully) I can't find the created docs.
I read the documentation which says there is destinationDir property but I'm unable to set it using Gradle.
I tried following this SO question in order to create a custom Gradle task but without success.
How can I set the destinationDir in order to get the generated docs?
Edit:
The (automatic generated) settings.gradle is:
buildscript {
dependencies {
classpath group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "1.5.0"
classpath group: "net.saliman", name: "gradle-properties-plugin", version: "1.4.6"
}
repositories {
maven {
url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
}
}
}
apply plugin: "net.saliman.properties"
apply plugin: "com.liferay.workspace"
I'm pretty sure that com.liferay.gradle.plugins.workspace includes the javadoc plugin. Furthermore, Liferay also automatically creates an empty build.gradle where I put:
apply plugin: 'java'
task api(type: Javadoc) {
source = sourceSets.main.allJava
destinationDir = new File(buildDir, "/api")
}
Launching the api Gradle task the javadoc plugin is not executed
I am new to GAE. I would like to use the asynchronous version of fetch (of package "com.google.appengine.api.urlfetch.*"), which is named "fetchAsync()" according to API documentation at here:
https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/urlfetch/URLFetchService
But in my java code, it seems no method named "fetchAsync()" -- it says "Cannot resolve method 'fetchAsync(com.google.appengine.api.urlfetch.HTTPRequest)". Below is my java code:
URL url = new URL("https://www.bitesquad.com" + href);
HTTPRequest request = new HTTPRequest(url, HTTPMethod.GET);
HTTPResponse response = URLFetchServiceFactory.getURLFetchService().fetchAsync(request);
I am sure that I imported everything needed because it is okay to run "fetch()". I am thinking about if I didn't include the appropriate version of GAE in my build.gradle or I missed anything in it. Or maybe Google didn't update the documentation? Below is my build.gradle:
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:+'
compile "org.apache.httpcomponents:httpclient:4.5.3"
compile "org.apache.commons:commons-lang3:3.5"
compile "com.google.code.gson:gson:2.8.0"
// https://mvnrepository.com/artifact/com.google.appengine/appengine-api-1.0-sdk
compile group: 'com.google.appengine', name: 'appengine-api-1.0-sdk', version: '1.2.0'
testCompile 'junit:junit:4.12'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
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
}
//tools.cloudSdkHome = '/Applications/google-cloud-sdk'
}
group 'xxx'
version 'xxx'
sourceCompatibility = 1.7 // App Engine Standard uses Java 7
targetCompatibility = 1.7 // App Engine Standard uses Java 7
Thank you in advance!
I found the answer: change the version to the newest one as follows:
compile group: 'com.google.appengine', name: 'appengine-api-1.0-sdk', version: '1.9.53'
(from 1.2 to 1.9)
I'm currently trying to include Project Lombok helper into my Gradle project, but while following their instructions for Gradle within my build.gradle, I'm getting the following error:
Error:(11, 0) Build script error, unsupported Gradle DSL method found: 'provided()'!
Possible causes could be:
you are using Gradle version where the method is absent
you didn't apply Gradle plugin which provides the method
or there is a mistake in a build script
My current build.gradle file:
apply plugin: 'java'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
provided "org.projectlombok:lombok:1.14.4"
testCompile group: 'junit', name: 'junit', version: '4.11'
}
As of release 2.12, provided scope is called compileOnly
Old answer:
Provided scope is available in 'war' plugin (http://www.gradle.org/docs/current/userguide/war_plugin.html , providedCompile ) If You don't want to use the 'war' plugin, there is also an opened JIRA issue regarding 'provided' scope http://issues.gradle.org/browse/GRADLE-784 , suggested workaround is to create Your own cofiguration:
configurations {
provided
}
and set it to be used with your compilation classpath:
sourceSets {
main {
compileClasspath += configurations.provided
}
}
Check your app level gradle file. If any line looks like this:
compile dependency.gson provided dependency.javaxAnnotation
Edit it like this:
compile dependency.gson
provided dependency.javaxAnnotation
It should work.
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.