Chinese output of Gradle Run is displayed as "????????", while Java Run output is fine.
Output of Gradle run
?????
\u5f9e\u51b7\u6c23\u8d77\u6548
?????
Output of Java run
從冷氣起效
\u5f9e\u51b7\u6c23\u8d77\u6548
從冷氣起效
The Gradle project with Eclipse. Chinese output of Java Run can be displayed after setting "Properties" > "Resource" > "Text file encoding" to UTF-8.
Here is the Java code.
package testgradle;
import org.apache.commons.text.StringEscapeUtils;
public class Test {
public static void main(String[] args) {
String origin = "從冷氣起效";
String input = "\\u5f9e\\u51b7\\u6c23\\u8d77\\u6548";
String result = StringEscapeUtils.unescapeJava("\\u5f9e\\u51b7\\u6c23\\u8d77\\u6548");
System.out.println(origin);
System.out.println(input);
System.out.println(result);
}
}
I have tried to modify build.gradle file, but still the output of Gradle run is not as expected.
build.gradle
plugins {
id 'java'
id 'application'
id 'java-library'
}
jar {
manifest {
attributes 'Main-Class': 'testgradle.Test'
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
application {
mainClassName = 'testgradle.Test'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
tasks.withType(Test) {
systemProperty "file.encoding", "UTF-8"
}
javadoc.options.encoding = 'UTF-8'
compileJava.options.encoding = 'UTF-8'
repositories {
jcenter()
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:28.2-jre'
implementation 'org.apache.commons:commons-text:1.9'
testImplementation 'junit:junit:4.12'
}
Please provide solution to solve the problem. Thanks!
Related
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
maven { url "https://maven.google.com" }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0 '
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
maven { url "https://maven.google.com" }
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I am getting the following :
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'android'.
Could not resolve all files for configuration ':classpath'.
Could not resolve com.android.tools.build:gradle:4.2.0 .
Required by:
project :
> Could not resolve com.android.tools.build:gradle:4.2.0 .
> Could not get resource 'https://dl.bintray.com/kotlin/kotlin-eap/com/android/tools/build/gradle/4.2.0%20/gradle-4.2.0%20.pom'.
> Could not GET 'https://dl.bintray.com/kotlin/kotlin-eap/com/android/tools/build/gradle/4.2.0%20/gradle-4.2.0%20.pom'. Received status code 502 from server: Bad Gateway
Does anyone
have an idea what the issue is,
how to fix it
I'm trying to set up spring cloud turbine amqp and hystrix dashboard. But when I start all applications hystrix dashboard doesn't show me anything:
hystrix-dashboard-screenshot-link
But when I open turbine stream link, I see not empty data:
turbine-stream-data-screenshot-link
When I stop my turbine service and run sample: https://github.com/spring-cloud-samples/turbine
It's working:
working-hystrix-dashboard-screenshot-link
So, the problem is in the my turbine service.
This is the TurbineApplication.java:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.stream.EnableTurbineStream;
#EnableTurbineStream
#SpringBootApplication
public class TurbineApplication {
public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class, args);
}
}
This is the application.yml:
server:
port: ${PORT:8989}
eureka:
user:
name: "{cipher}6c627b546202f13ffa9e3edf39974a3bfca5d615f58dcbfc23065661968b13c5"
password: "{cipher}75efd89c7c4d79220a5b3f35e9ad692a69c820fa0b99e9c48ae9433d45ba016db808ab9dce78382235e529291f8aa0be"
instance:
preferIpAddress: true
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://${eureka.user.name}:${eureka.user.password}#127.0.0.1:8761/eureka/
This is bootstrap.yml:
spring:
application:
name: turbine-service
And this is gradle.build:
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
dockerPluginVersion = '1.2'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("se.transmode.gradle:gradle-docker:${dockerPluginVersion}")
}
}
apply plugin: 'java'
apply plugin: 'docker'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.pda'
jar {
baseName = 'turbine-service'
version = 'latest'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
ext {
springCloudVersion = 'Edgware.RELEASE'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.cloud:spring-cloud-starter-turbine-stream')
compile('org.springframework.cloud:spring-cloud-starter-stream-rabbit')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
task buildDocker(type: Docker, dependsOn: build) {
push = false
applicationName = jar.baseName
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
It looks like the problem is in the dependencies version.
The problem is in the Edgware.RELEASE (and Edgware.SR1) version. It's need to downgrade spring cloud version (for example, to Dalston.SR5), or use Edgware.BUILD-SNAPSHOT.
Description: https://github.com/spring-cloud/spring-cloud-netflix/issues/2637
A domain object is setup as the following:
#Data
#NoArgsConstructor
#Entity
public class Foo {
...
public Foo(...){
...
}
...
}
It is fine when I run a build with a set of tests. When I only run the test class, however, I get the following error:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: No default constructor for entity: : com.abc.myapp.Foo; nested exception is org.hibernate.InstantiationException: No default constructor for entity: : com.abc.myapp.Foo
The project setup is with Spring Boot generated by the project generator on spring.io. And the following is the Gradle build file:
buildscript {
ext {
springBootVersion = '1.5.0.RC1'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle- plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'spring-data-samples'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-actuator-docs')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('com.h2database:h2')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
}
And IDE is Intellij Idea.
What is missing?
I am using gradle application plugin to run my application. Below is my build.gradle:
group 'demo.jersey'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = 1.5
mainClassName = "com.example.Main"
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.22.1'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
When I run gradle run, I can see my application is launched but it got shutdown immediately. Below is my Main class. Do you know how to block the application without shutting down?
package com.example;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import java.io.IOException;
import java.net.URI;
public class Main {
public static final String BASE_URI = "http://localhost:8080/myapp/";
public static HttpServer startServer() {
final ResourceConfig rc = new ResourceConfig().packages("com.example");
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}
public static void main(String[] args) throws IOException {
final HttpServer server = startServer();
System.out.println(String.format("Jersey app started with WADL available at "
+ "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
System.in.read();
server.stop();
}
}
It stops because you invoke server.stop(); explicitly so the program finishes. Comment out this line and it will keep on running and listening for incoming requests.
I have a root project with three subprojects
root
|
|-subA
|-subB
|-subB
the build.gradle file in root has this content
allprojects {
}
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.zeromq:jeromq:0.3.+'
compile files('../lib/tibrvj.jar')
}
eclipse {
classpath {
downloadJavadoc=true
}
}
sourceSets {
main.java.srcDirs = ['src/main/java']
main.resources.srcDirs = ['src/main/resources']
test.java.srcDirs = ['src/test/java']
test.resources.srcDirs = ['src/test/resources']
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2'
}
task srcDirs << {
subprojects.sourceSets.main.java.srcDirs.each{f -> println(f)}
subprojects.sourceSets.main.resources.srcDirs.each{f -> println(f)}
subprojects.sourceSets.test.java.srcDirs.each{f -> println(f)}
subprojects.sourceSets.test.resources.srcDirs.each{f -> println(f)}
}
I do not know how I can create all the directories with this config. The other gradle.build files are empty at the moment
Unless you're trying to change from the defaults, you shouldn't need to set the sourceSets directories in the subprojects.
Have you tried something like:
subprojects {
task makeSrcDirs << {
sourceSets.main.java.srcDirs*.mkdirs()
sourceSets.main.resources.srcDirs*.mkdirs()
sourceSets.test.java.srcDirs*.mkdirs()
sourceSets.test.resources.srcDirs*.mkdirs()
}
}