Intellij-IDEA gradle templates - java

How can I change the template of "build.gradle" in IntelliJ IDEA 15.0.1 ?
I'd like to delete "sourceCompatibility", to add 'idea' plugin, and to modify the version of JUnit.
I'd tried to modify "Gradle Build Script" as below,
Perference > Editor > File and Code Templates > Gradle Build Script
apply plugin: 'java'
apply plugin: 'idea'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.12'
}
but I got a build.gradle as followed
apply plugin: 'java'
apply plugin: 'idea'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.12'
}
apply plugin: 'java'
sourceCompatibility = 1.5
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Best Regards,
-Mitsutaka Ohisa

The preferences you are interest are hard-coded in IDEA JetBrains gradle plugin:
<IDEA_base>\plugins\gradle\lib\gradle.jar\org\jetbrains\plugins\gradle\frameworkSupport\GradleJavaFrameworkSupportProvider.class

Related

Facing issue while running gradle clean build

I am using Gradle 5 as my build tool for my Java application. I am getting below error while running gradle clean build.
Could not set unknown property 'stopPort' for root project '1-SimpleServlet' of type org.gradle.api.Project
PFA error image
Please find build.gradle file
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'jetty'
stopPort = 8081
stopKey = 'stopKey'
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5'
providedCompile 'org.apache.commons:commons-io:1.3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Pleas help me resolve this issue.
The jetty plugin has been deprecated with Gradle 3.0 and eventually been removed in Gradle 4.0 (Release Notes, Github Issue). Since you're using Gradle 5, I suggest to have a look at the official Building Java Web Applications guide which uses the gretty plugin.
Example build.gradle:
plugins {
id 'war'
id 'eclipse'
id 'org.gretty' version '3.0.1'
}
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
testCompile 'junit:junit:4.12'
}

Can't generate war - Java EE 8

After create a new Java EE project - in IntelliJ - new project -> Gradle from left list -> next -> next
I fill 2 files
build.gradle:
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'war'
apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
group 'com.random'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
providedCompile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
and
#Path("/reservation")
public class ReservationWebService {
#GET
public Response listReservations() {
return Response.ok("hello").build();
}
}
now I'm trying to generate war by:
gradle war in terminal and I got:
'gradle' is not recognized as an internal or external command,
operable program or batch file.
How to generate war ?

How to setup Amazon Polly SDK with Gradle in IntetlliJ

I am trying to setup AWS Polly Java SDK with Gradle in IntelliJ by following this. I have already created a simple Spring Boot application using the spring intializr, so I added the items specified in the tutorial to my build.gradle file. When try to import
import com.amazonaws.services.polly.AmazonPollyClient
IntelliJ fails to resolve name polly.
This is my full build.gradle file
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'io.ai.vivid'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.228'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile 'com.amazonaws:aws-java-sdk-s3'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Also IntelliJ complains that it can't resolve the name manvenBom in my build.gradle. I have already tried SO solutions to this like invalidate cache/restart but could not resolve the issue.
I used your build.gradle file to replicate the issue and was able to import AmazonPollyClient after making the following changes to the dependencies
dependencies {
compile 'com.amazonaws:aws-java-sdk-s3'
compile group: 'com.amazonaws', name: 'aws-java-sdk-polly', version: '1.11.67'
The Gradle version used 4.8

Including javafx.util.Pair as a dependency in gradle

I have a springboot app that I developed using oracle JDK and it uses the javafx.util.pair class. When the jar built is run on a system with OpenJDK it cannot find this class. How can i package this dependency with my jar? I am using gradle. Here is my build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE")
}
}
description = "CF Service Broker using Java / Spring"
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'cf-tile'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-devtools")
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('com.jayway.jsonpath:json-path')
testCompile group: 'junit', name: 'junit', version: '4.12'
}
I don't believe you can import javafx utils via gradle but you can, for platforms that do not include it in their version of OpenJDK, use openjfx.
For example you can install it in ubuntu using:
sudo apt-get install openjfx

cannot resolve symbol 'SpringRunner' for java Spring junit

I'm trying to write a junit test for my first java project using Spring framework. I have searched online how to include the dependency in order to use it but keep encountering this warning:
Cannot resolve symbol 'SpringRunner'
in intelliJ IDEA. So what is missing?
Here is my dependency file for gradle.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle- plugin:1.5.1.RELEASE")
classpath("org.springframework:spring-test:4.0.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
testCompile("org.springframework:spring-test:4.0.3.RELEASE")
compile('com.google.maps:google-maps-services:0.1.18')
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-data-mongodb")
compile("org.springframework.boot:spring-boot-starter-web")
testCompile('junit:junit:4.12')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile("org.springframework.security:spring-security-test")
}
try adding org.springframework.test.context.junit4.SpringRunner;

Categories