The official tutorial from Ktor.io doesn't work, I tried it.
It's my first deploy. Thanks for help.
My gradle file (kts):
import com.google.cloud.tools.gradle.appengine.appyaml.AppEngineAppYamlExtension
buildscript {
dependencies {
classpath("com.google.cloud.tools:appengine-gradle-plugin:2.2.0")
}
}
apply {
plugin("com.google.cloud.tools.appengine")
}
plugins {
// Support for Kotlin
id("org.jetbrains.kotlin.jvm") version "1.3.61"
// Support for building a CLI application
application
// Documentation
id("org.jetbrains.dokka") version "0.10.1"
war
// id("com.improve_future.harmonica") version "1.1.24"
}
application {
mainClassName = "com.easythings.parkkometr.AppKt"
group = "com.easythings"
version = "0.0.1"
}
sourceSets {
main {
java.srcDir("app/main/src")
resources.srcDir("app/main/resources")
}
test {
java.srcDir("app/test/src/")
resources.srcDir("app/test/resources/")
}
}
repositories {
jcenter()
maven { setUrl("https://kotlin.bintray.com/ktor") }
}
dependencies {
val ktorVersion: String by project
val logbackVersion: String by project
val exposedVersion: String by project
val pgVersion: String by project
val spekVersion: String by project
val sendGridVersion: String by project
val assertJVersion: String by project
// Kotlin ============================================================================
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// Libs ============================================================================
// Ktor - framework
implementation("io.ktor", "ktor-server-jetty", ktorVersion)
implementation("io.ktor", "ktor-server-core", ktorVersion)
implementation("io.ktor", "ktor-server-host-common", ktorVersion)
implementation("io.ktor", "ktor-auth", ktorVersion)
implementation("io.ktor", "ktor-auth-jwt", ktorVersion)
implementation("io.ktor", "ktor-gson", ktorVersion)
implementation("io.ktor", "ktor-network-tls-certificates", ktorVersion)
// Logback - application logger
implementation("ch.qos.logback", "logback-classic", logbackVersion)
// Exposed - orm
implementation("org.jetbrains.exposed", "exposed-core", exposedVersion)
implementation("org.jetbrains.exposed", "exposed-dao", exposedVersion)
implementation("org.jetbrains.exposed", "exposed-jdbc", exposedVersion)
implementation("org.jetbrains.exposed", "exposed-jodatime", exposedVersion)
// Postgresql - database driver
implementation("org.postgresql", "postgresql", pgVersion)
// SendGrid - mailer
implementation("com.sendgrid", "sendgrid-java", sendGridVersion)
// Deploy ============================================================================
providedCompile("com.google.appengine", "appengine", "1.9.60")
// Tests ============================================================================
}
tasks {
dokka {
outputDirectory = "$buildDir/docs/dokka"
outputFormat = "html"
}
test {
useJUnitPlatform {
includeEngines("spek2")
}
}
}
configure<AppEngineAppYamlExtension> {
deploy {
setAppEngineDirectory(".")
version = "1"
projectId = "XYZ-placeholder"
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
stage {
setAppEngineDirectory(".")
}
}
My app.yaml file:
runtime: java
env: flex
handlers:
- url: /.*
script: this field is required, but ignored
I get information that the deploy has finished successfully, but I get a 403 error when I call gcloud app browse.
HTTP ERROR 403 Problem accessing /. Reason:
Forbidden
I think that my app doesn't start and it's the error from Jetty, but I don't know how to check/confirm and fix it.
The task appengineRun doesn't exist in this version GAE.
First of all, the provided Ktor tutorial for App Engine Standard environment, but you have "flex" env in the app.yaml file.
Also I would like to recommend you follow the official more informative Google Cloud documentation for Ktor.
Related
After deploying my Google Endpoints API I get the error below even if I hit just the server url / or /_ah/warmup
Uncaught exception from servlet
java.lang.NoSuchMethodError: com.google.api.Service.hasQuota()Z
at com.google.api.control.model.MethodRegistry.extractQuota(MethodRegistry.java:290)
at com.google.api.control.model.MethodRegistry.<init>(MethodRegistry.java:72)
at com.google.api.control.ConfigFilter.init(ConfigFilter.java:89)
The crazy thing is that this happens intermittently. Sometimes the deploy just works, but most times it fails.
This used to work fine as is until March 1st, so I rolled back the gcloud components version as well, but still get the same error.
Tried upgrading to the latest version if the appengine and endpoints libaries, but still get the error below.
EDIT-1
Here is the build.gradle for reference
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
// App Engine Gradle plugin
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.4.1'
// Endpoints Frameworks Gradle plugin
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:2.1.0'
}
}
// Dev
def projectIdValue = 'dev-sample-api'
repositories {
mavenCentral()
jcenter()
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceSets {
main {
java {
srcDirs 'src/main/java'
}
}
}
dependencies {
// App Engine API
implementation group: 'com.google.appengine', name: 'appengine-api-1.0-sdk', version: '1.9.86'
// Endpoints Frameworks v2.0
implementation ('com.google.endpoints:endpoints-framework:2.2.2') {
exclude group: 'org.slf4j', module: 'slf4j-nop'
}
implementation group: 'com.google.endpoints', name: 'endpoints-management-control-appengine', version: '1.0.14'
implementation group: 'com.google.endpoints', name: 'endpoints-framework-auth', version: '1.0.14'
implementation group: 'com.google.protobuf', name: 'protobuf-java-util', version: '3.15.6'
implementation group: 'io.grpc', name: 'grpc-stub', version: '1.36.0'
implementation group: 'io.grpc', name: 'grpc-protobuf', version: '1.36.0'
// App Engine and Endpoint dependencies
compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
implementation 'jstl:jstl:1.2'
implementation group: 'javax.inject', name: 'javax.inject', version: '1'
// Logging
implementation 'org.slf4j:slf4j-api:1.7.30'
implementation 'org.slf4j:slf4j-jdk14:1.7.30'
// Objectify for data storage and access
implementation 'com.googlecode.objectify:objectify:5.1.9'
// Common Utils and Libraries
implementation 'com.google.guava:guava:20.0'
implementation 'commons-validator:commons-validator:1.6'
implementation 'joda-time:joda-time:2.10.8'
implementation group: 'com.darwinsys', name: 'hirondelle-date4j', version: '1.5.1'
}
endpointsServer {
// Endpoints Framework Plugin server-side configuration
hostname = "${projectIdValue}.appspot.com"
}
// this replaces the ${endpoints.project.id} in appengine-web.xml and web.xml
task replaceProjectId(type: Copy) {
from 'src/main/webapp/WEB-INF/'
include '*.xml'
into "build/exploded-${archivesBaseName}/WEB-INF"
expand(endpoints:[project:[id:projectIdValue]])
filteringCharset = 'UTF-8'
}
assemble.dependsOn replaceProjectId
appengine {
deploy { // deploy configuration
version = "GCLOUD_CONFIG"
projectId = "GCLOUD_CONFIG"
def promoteProp = findProperty("appengine.deploy.promote")
if (promoteProp != null) {
promote = new Boolean(promoteProp)
}
}
run {
host = "0.0.0.0"
port = 8080
}
}
Just for the records - correct command line would be:
gcloud components update
Closing this based on suggestion by #RafaelLemos.
"Maybe this was a problem with an older version of some component"
Not reproducible. Probable fix
gcloud components update
I tried to upgrade my react native project to the newest version (0.59.2). Unfortunately, now when trying to run react-native run-android im getting this error:
Could not determine the dependencies of task ':app:preDebugBuild'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
> Could not resolve project :react-native-camera.
Required by:
project :app
> Cannot choose between the following variants of project :react-native-camera:
- generalDebugRuntimeElements
- mlkitDebugRuntimeElements
All of them match the consumer attributes:
- Variant 'generalDebugRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'generalDebug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Found react-native-camera 'general' but wasn't required.
- Variant 'mlkitDebugRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'mlkitDebug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Found react-native-camera 'mlkit' but wasn't required.
I have already tried to create a new project however this results in the same error.
Reinstalling the node modules didn't help either.
On iOS it works fine.
Insert the following lines in android/app/build.gradle
android {
...
defaultConfig {
...
missingDimensionStrategy 'react-native-camera', 'general' <-- insert this line
}
}
Please insert the following line in android/app/build.gradle inside defaultConfig block either
missingDimensionStrategy 'react-native-camera', 'general'
or
missingDimensionStrategy 'react-native-camera', 'mlkit'
Add jitpack to android/build.gradle
allprojects {
repositories {
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
}
Complete guide
Could not resolve project :react-native-camera. on Android
Hope this helps.
Step 1:
Change the class path in android/build.gradle in dependencies tag to this:
classpath 'com.android.tools.build:gradle:3.3.0'
Step:2:
Change the gradle version in android/gradle/wrapper/gradle-wrapper.properties to this:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
Step 3:
In the android/app/build.gradle add this at the top:
defaultConfig {
missingDimensionStrategy 'react-native-camera', 'general'
}
}
Step 4:
Also add these two lines:
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
Camera works now.
It is simple to resolve by adding missingDimensionStrategy attribute in defaultConfig tag in android/app/build.gradle.
android {
...
defaultConfig {
...
missingDimensionStrategy 'react-native-camera', 'general'
}
}
If you are still having the same issue then you have to do the following steps.
Ensure that your gradle build tool version is greater than 3.3.0. You can use 3.4.1 for this purpose. Change the gradle build tool version from android/build.gradle file buildscript dependencies attributes.
buildscript {
...
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
}
}
Also have to change the gradle wrapper to 4.4 or later. You can change the gradle version in android/gradle/wrapper/gradle-wrapper.properties to this
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Finally add the following lines in repositories tag of android/build.gradle
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
We received an email from Google App Engine to upgrade to Java 8 from Java 7. We have followed the steps in:
https://cloud.google.com/appengine/docs/standard/java/migrating-to-java8
But after deploying our App Engine back-end it fails to start with the following error:
org.datanucleus.metadata.MetaDataManager initialiseFileMetaDataForUse:
Found Meta-Data for class ... but this class
is not enhanced!! Please enhance the class before running DataNucleus.
(MetaDataManager.java:1144)
org.datanucleus.exceptions.NucleusUserException: Found Meta-Data for
class ... but this class is not enhanced!!
Please enhance the class before running DataNucleus. at
org.datanucleus.metadata.MetaDataManager.initialiseClassMetaData(MetaDataManager.java:2593)
at
org.datanucleus.metadata.MetaDataManager.initialiseFileMetaData(MetaDataManager.java:2544)
at
org.datanucleus.metadata.MetaDataManager.initialiseFileMetaDataForUse(MetaDataManager.java:1140)
at
org.datanucleus.metadata.MetaDataManager.loadPersistenceUnit(MetaDataManager.java:986)
at
org.datanucleus.api.jpa.JPAEntityManagerFactory.initialiseNucleusContext(JPAEntityManagerFactory.java:754)
at
org.datanucleus.api.jpa.JPAEntityManagerFactory.initialise(JPAEntityManagerFactory.java:417)
at
org.datanucleus.api.jpa.JPAEntityManagerFactory.(JPAEntityManagerFactory.java:380)
at
org.datanucleus.api.jpa.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:91)
at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:150)
at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:70)
This is our build.gradle:
buildscript { // Configuration for building
repositories {
mavenCentral()
jcenter() // Bintray's repository - a fast Maven Central mirror & more
}
dependencies {
// App Engine Gradle plugin
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+'
}
}
repositories {
mavenCentral()
jcenter()
}
apply plugin: 'java'
apply plugin: 'war'
//apply plugin: 'appengine'
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
appengine { // App Engine tasks configuration
deploy { // deploy configuration
version = findProperty("appengine.deploy.version")
def promoteProp = findProperty("appengine.deploy.promote")
if (promoteProp != null) {
promote = new Boolean(promoteProp)
}
}
}
configurations {
compile.exclude module: 'guava-jdk5'
}
dependencies {
implementation 'jstl:jstl:1.2'
implementation group: 'com.google.appengine', name: 'appengine-api-1.0-sdk', version: '+'
implementation group: 'com.google.endpoints', name: 'endpoints-framework', version: '+'
implementation 'com.google.appengine.orm:datanucleus-appengine:+' //2.1.2'
implementation 'javax.servlet:servlet-api:2.5'
implementation 'javax.inject:javax.inject:1'
implementation 'javax.transaction:jta:1.1'
implementation 'com.ganyo:gcm-server:1.0.2'
implementation 'org.json:json:20140107'
implementation 'org.apache.httpcomponents:httpmime:+'
implementation 'org.apache.geronimo.specs:geronimo-jpa_2.0_spec:1.0'
// Persistence
// implementation 'org.ow2.asm:asm:4.0'
implementation 'javax.jdo:jdo-api:+' //3.0.1'
implementation 'org.datanucleus:datanucleus-api-jpa:3.1.3'
implementation 'org.datanucleus:datanucleus-api-jdo:3.1.3' //5.0.1'
implementation 'org.datanucleus:datanucleus-enhancer:+' //3.1.1'
implementation 'org.datanucleus:datanucleus-core:3.1.3'
implementation 'org.hibernate:hibernate-validator:5.2.4.Final'
implementation 'com.google.api-client:google-api-client:+'
implementation 'com.google.api-client:google-api-client-android:+'
implementation 'com.google.http-client:google-http-client:+'
implementation 'com.google.http-client:google-http-client-android:+'
}
task datanucleusEnhance {
description "Enhance JPA model classes using DataNucleus Enhancer"
dependsOn compileJava
doLast {
// define the entity classes
def entityFiles = fileTree(sourceSets.main.output.classesDir).matching {
include '/*.class'
}
println "Enhancing with DataNucleus the following files"
entityFiles.getFiles().each {
println it
}
// define Ant task for DataNucleus Enhancer
ant.taskdef(
name : 'datanucleusenhancer',
classpath : sourceSets.main.runtimeClasspath.asPath,
// classname : 'org.datanucleus.enhancer.EnhancerTask'
// the below is for DataNucleus Enhancer 3.1.1
classname : 'org.datanucleus.enhancer.tools.EnhancerTask'
)
// run the DataNucleus Enhancer as an Ant task
ant.datanucleusenhancer(
classpath: sourceSets.main.runtimeClasspath.asPath,
verbose: true,
api: "JDO") {
entityFiles.addToAntBuilder(ant, 'fileset', FileCollection.AntType.FileSet)
}
}
}
classes.dependsOn(datanucleusEnhance)
This works as soon as we switch back to Java 7.
i'm trying to run my app using this tutorial :
http://guides.grails.org/building-a-react-app/guide/index.html
there is the the git repository
https://github.com/tetar998/building-a-react-app/tree/master/complete
but i m stuck with this error
Could not resolve view with name '/index' in servlet with name 'grailsDispatcherServlet'
i am currently working with
- groovy 2.4.11
- java 8u152
- grails 3.3.0
and in there is my controller/demo/urlmappings
package demo
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?(.$format)?"{
constraints {
// apply constraints here
}
}
"/"(view: '/index')
"500"(view: '/error')
"404"(view: '/notFound')
}
}
Any suggestion?
I've been utilizing the url provided to me by the google-app-engine, i.e. "projectname-id.appspot.com" for my project. I had previously purchased a custom domain from GoDaddy, and I followed the steps at the following link to verify ownership of the domain name within the Google Cloud Platform, add the domain to my Google App Engine Project, and update my DNS settings in GoDaddy to point to the listed CNAME/server combination. https://cloud.google.com/appengine/docs/go/console/using-custom-domains-and-ssl
When I visit my custom domain, a website page is served, but it's always a 404. The "projectname-id.appspot.com" url still works correctly, and when I look at the log statements in the Google App Engine, it receives the request from both my custom domain and the appspot domain - which seems to suggest the domain dns was updated properly. See image below, where the 404 is from the custom domain and the 200 is from the appspot url:
Google App Engine Logs
Is there anything else I have to do? The backend is written in Go, and we're using the Mux Router. Do I need to modifiy my app.yaml file or edit my routes somehow? Any suggestions would be greatly appreciated.
Here I've included some code snippets I use to initialize my server:
App.yaml
version: alpha-001
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
env_variables:
PRODUCTION: 'TRUE'
DATASTORE_DATASET: 'app-id'
DATASTORE_HOST: 'http://localhost:8043'
DATASTORE_EMULATOR_HOST: 'localhost:8043'
DATASTORE_PROJECT_ID: 'app-id'
GOOGLE_APPLICATION_CREDENTIALS: './app-string.json'
Initializing the WebConsole (Server):
func init() {
// Web Server for API Endpoints
flag.Parse()
var server *web_console.WebConsole
if prod := os.Getenv("PRODUCTION"); prod == "FALSE" {
server = web_console.NewWebConsole(false)
} else {
server = web_console.NewWebConsole(true)
}
server.Run()
}
WebConsole.go
type WebConsole struct {
prod bool
Mux *mux.Router
DbMap *gorp.DbMap
Client *datastore.Client
}
func NewWebConsole(prod bool) *WebConsole {
return &WebConsole{
prod: prod,
}
}
func (w *WebConsole) Run() {
w.dbInit()
w.routesInit()
}
func (w *WebConsole) dbInit() {
// Configure SQL connection
// Code removed for privacy reasons
}
func (w *WebConsole) routesInit() {
// Configure routes with Mux
w.Mux = mux.NewRouter()
api.AddCertChallengeApis(w.Mux)
// The path "/" matches everything not matched by some other path.
// Checkout: http://stackoverflow.com/questions/26581231/google-cloud-go-handler-without-router-gorilla-mux
// for more details
http.Handle("/", w.Mux)
}
Api Package File for Routing
package api
import (
"github.com/gorilla/mux"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
"net/http"
"strings"
)
func AddCertChallengeApis(r *mux.Router) {
r.Schemes("http")
r.HandleFunc("/", defaultHandler())
}
func defaultHandler() http.HandlerFunc {
return func(rw http.ResponseWriter, req *http.Request) {
// Construct new app engine context
c := appengine.NewContext(req)
log.Infof(c, "App ID: %v", appengine.AppID(c))
rw.Header().Set("Content-Type", "text/plain")
rw.Write([]byte("hi, welcome to my website yo"))
log.Infof(c, "Hit the website")
}
}
I have done custom domains on appengine/go before, and there is nothing else you should have to do. I would try removing this line, though,
r.Schemes("http")
in case it is something https related.