cannot resolve symbol 'SpringRunner' for java Spring junit - java

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;

Related

Need to use no.nils.wsdl2java for gradle 7.0.2 and JDK 8.0.332.9

I need to use wsdl2 plugin for gradle 7.0.2 and my JDK version is 8.0.332.9
Below is the lines of code in build.gradle I wrote but I am getting an error Failed to apply plugin no.nils.wsdl2java > Configuration with name 'compile' not found.
Can anyone please help me with this?
buildscript {
ext {
springBootVersion = '2.7.0'
sys_user = System.env.SYS_USER
sys_pass = System.env.SYS_PASSWORD
}
repositories {
maven {
// url
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.1.1')
classpath('org.jfrog.buildinfo:build-info-extractor-gradle:4.21.0')
classpath("org.openapitools:openapi-generator-gradle-plugin:5.1.1")
classpath("no.nils:wsdl2java:0.12")
}
}
apply plugin: 'java'
apply plugin: 'org.sonarqube'
apply plugin: 'jacoco'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'org.openapi.generator'
apply plugin: 'no.nils.wsdl2java'

Mulit module with each module provide rest service in gradle with spring

I am try to create multi module spring project with Gradle.
Each module has independent rest api service.
I haven't idea too much with Gradle.
library-application can access by application module but not able to execute simultaneously API of each modules using tomcat.
Module 1st : application
File settings.gradle:
rootProject.name = 'application'
include ':library-application'
project(':library-application').projectDir = new File('../library-application')
File build.gradle:
buildscript {
ext { springBootVersion = '2.1.3.RELEASE' }
repositories { jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.0',
classpath 'org.apache.openjpa:openjpa-all:2.4.1'
classpath 'at.schmutterer.oss.gradle:gradle-openjpa:0.2.0'
}
}
plugins {
id "io.spring.dependency-management" version "1.0.5.RELEASE"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'tomcat'
bootJar {
baseName = 'gs-multi-application'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
repositories { mavenCentral() }
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
compile project(':library-application')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Module 2nd : library-application
File build.gradle:
buildscript {
repositories { jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.0',
classpath 'org.apache.openjpa:openjpa-all:2.4.1'
classpath 'at.schmutterer.oss.gradle:gradle-openjpa:0.2.0'
}
}
plugins {
id "io.spring.dependency-management" version "1.0.5.RELEASE"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'tomcat'
plugins { id "io.spring.dependency-management" version "1.0.5.RELEASE" }
ext { springBootVersion = '2.1.3.RELEASE' }
jar {
baseName = 'gs-multi-library'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
repositories { mavenCentral() }
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
In general, root project in Gradle does nothing but only hold a overall build.gradle and settings.properties to group child projects together. Module planning should be done via managing dependencies of child projects, not the folder structure.
Try to organize your projects in this way:
root_project (very simple project doing nothing)
- library-application
- Provide service controllers
- application (depends on library-application)
- Provide SpringBootApplication

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

Gradle parent project not using child repositories?

That's how I would interpret it. I have a multi-project build with 2 modules: codec and content. When I try to build the project it says it can't find repositories. But when building individual modules, no errors. Also, evaluationDependsOn(':codec') doesn't seem to help.
Could not resolve all dependencies for configuration ':compileClasspath'.
> Cannot resolve external dependency commons-codec:commons-codec:1.5 because no repositories are defined.
Required by:
:multiproject-unified:unspecified > multiproject-unified:codec:unspecified
parent build.gradle:
apply plugin: 'java'
dependencies {
compile project(':codec')
compile project(':content')
}
settings.gradle
include 'codec',
'content'
:codec build.gradle
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'commons-codec:commons-codec:1.5'
}
:content build.gradle
apply plugin: 'java'
repositories {
mavenCentral()
}
Try declaring your repositories for the entire project in the parent:
allprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
}

Class in main/resources not found

I'm using the Spring Boot gradle plugin to build an executable war. I have a FindResource.java class in src/main/resources to locate files:
FindResource.class.getResource(templateName).toURI()
When I execute gradle build I get an error, that the class FindResource cannot be resolved. Do I need to the the Spring Boot gradle plugin, that it should also use classes from the resources directory. How can I do so?
My build.gradle looks as follows:
buildscript {
ext {
springBootVersion = '1.2.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
jar {
baseName = 'abc'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-jersey")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.apache.pdfbox:pdfbox:1.8.10")
compile('org.apache.poi:poi-ooxml:3.12')
compile('org.apache.poi:poi-scratchpad:3.12')
runtime("org.hsqldb:hsqldb")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
As mentioned in the comment class files to load need to be in src/main/java/ and not in src/main/resources. This link may help give you more information on the convention of this structure.

Categories