"mvn clean install" unable to resolve junit imports - spring

I had written a JUnit test case for a Service class in Spring Boot web application.
I have spring-boot-starter-test in my pom.xml but when I run "mvn clean install" the junit related imports are not resolving. The error is as below.
cannot find symbol
[ERROR] symbol: class Before
[ERROR] location: package org.junit
maven build is failing with this error.
When I run build project in eclipse it is working fine as I've added the junit library in project build path. but maven build is failing.

Related

Grails Example applications not working for Angular, Vue and React

I am in the learning process of Grails, and I have gotten the default example application HelloWorld work.
Running, building on Windows with WSL2 in OpenSUSE Leap 15.4.
Grails version 5.2.5
I then proceeded to try different profiles when creating the grails application, with Angular, React and Vue.
These did not go so well. Either something is missing from my configuration, JDK, Gradle, etc., and/or perhaps the generated projects need to be updated to use newer JDK and Gradle.
Perhaps I should report these problems on the Grails Profile GitHub.
https://github.com/grails-profiles/angular/issues
https://github.com/grails-profiles/react/issues
https://github.com/grails-profiles/vue/issues
Web
grails create-app grails-test-web --profile=web
Building and running the application works with both JDK-11/Gradle-7.2 and JDK-17/Gradle-7.6
Angular
grails create-app grails-test-angular --profile=angular
The project was created with Gradle-5.1.1, and I used JDK-11 to build it.
It will not build.
./gradlew bootRun --parallel
FAILURE: Build failed with an exception.
* Where:
Build file '/home/djviking/workspace/grails-test-angular/server/build.gradle' line: 19
* What went wrong:
A problem occurred evaluating project ':server'.
> Failed to apply plugin [class 'org.springframework.boot.gradle.plugin.SpringBootPlugin']
> Spring Boot plugin requires Gradle 6.8.x, 6.9.x, or 7.x. The current version is Gradle 5.1.1
Then I upgraded to Gradle 6.8.1, but that did not work either
> Configure project :server
Cannot resolve reloading agent JAR: Failed to resolve imported Maven boms: Cannot resolve external dependency org.springframework.boot:spring-boot-dependencies:2.7.5 because no repositories are defined.
Required by:
project :server
FAILURE: Build failed with an exception.
* Where:
Build file '/home/djviking/workspace/grails-test-angular/server/build.gradle' line: 19
* What went wrong:
A problem occurred evaluating project ':server'.
> Receiver class grails.util.Environment does not define or inherit an implementation of the resolved method 'abstract java.lang.Object getProperty(java.lang.String)' of interface groovy.lang.GroovyObject.
React
grails create-app grails-test-react --profile=react
The project was created with Gradle-6.9, and I used JDK-11 to build it.
It will not build/start
./gradlew server:bootRun
./gradlew client:start
Cannot resolve reloading agent JAR: Failed to resolve imported Maven boms: Cannot resolve external dependency org.springframework.boot:spring-boot-dependencies:2.7.5 because no repositories are defined.
Required by:
project :server
FAILURE: Build failed with an exception.
* Where:
Build file '/home/svmoe/workspace/grails-test-react/server/build.gradle' line: 20
* What went wrong:
A problem occurred evaluating project ':server'.
> Receiver class grails.util.Environment does not define or inherit an implementation of the resolved method 'abstract java.lang.Object getProperty(java.lang.String)' of interface groovy.lang.GroovyObject.
Vue
grails create-app grails-test-vue --profile=vue
The project was created with Gradle-6.9, and I used JDK-11 to build it.
It will not build the project.
./gradlew server:bootRun
./gradlew client:serve
> Configure project :server
Cannot resolve reloading agent JAR: Failed to resolve imported Maven boms: Cannot resolve external dependency org.springframework.boot:spring-boot-dependencies:2.7.5 because no repositories are defined.
Required by:
project :server
FAILURE: Build failed with an exception.
* Where:
Build file '/home/svmoe/workspace/grails-test-vue/server/build.gradle' line: 20
* What went wrong:
A problem occurred evaluating project ':server'.
> Receiver class grails.util.Environment does not define or inherit an implementation of the resolved method 'abstract java.lang.Object getProperty(java.lang.String)' of interface groovy.lang.GroovyObject.
Works with JDK 17, when I changed Gradle Wrapper to Gradle 7.6
./gradlew server:bootRun
I can access the URL, and I get a JSON structure.
Grails application running at http://localhost:8080 in environment: development
./gradlew client:serve
I can not access the URL from this. Neither on localhost.
App running at:
- Local: http://HOSTNAME:3000/
- Network: http://HOSTNAME:3000/

How do I instruct Spring Boot Devtools where to find dependencies in a Maven project

I've got a Spring Boot Maven project that creates an executable fat .war. I can run this .war using java -jar without any issues as all dependencies are located within the far .war.
However, I can't run the project with the Spring Boot Devtools using mvn spring-boot:run as it fails to find some dependencies at runtime and throws unhandled exceptions.
For example, we've got an indirect dependency on jaxb-runtime-2.3.1.jar which in turn has a dependency on jaxb-api.2.3.1.jar. Both .jars are present in the fat .war but if I run the project with mvn spring-boot:run it can find jaxb-runtime ok but fails to find jaxb-api with the message:
java.nio.file.NoSuchFileException: ~/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.1/jaxb-api-2.3.1.jar
Note, jaxb-api-2.3.1.jar is present in the maven cache at:
~/.m2/repository/javax/xml/bind/jaxb-api/2.3.1/jaxb-api-2.3.1.jar
however it seems to be looking for it in the same location as the parent jaxb-runtime-2.3.1.jar which is located at:
~/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.1/
There's a long list of similar exceptions that follow this pattern. It's quite a large project but here are some of the versions we're using:
Spring Boot: 2.1.9.RELEASE
spring-boot-maven-plugin: 2.1.9.RELEASE
maven-compiler-plugin: 3.8.1
spring-boot-devtools: not specified in pom
Why does spring-boot:run not locate dependencies in the same way as the maven build? How can I instruct it where to find these dependencies?

How to package a customized spring-boot starter without main class using maven

I created a customized spring-boot starter project and want to deploy it to a remote maven repo. When I run mvn clean package deploy, I got an error said:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.2.RELEASE:repackage (repackage) on project jcr-service-spring-boot-starter: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.2.RELEASE:repackage failed: Unable to find main class -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
In fact, I don't think it is necessary for a spring-boot starter project to have got a main class, because it will never be run alone.
Could everyone help to explain how I can package the project please?
The error message mentions the usage of the Spring Boot Maven Plugin. The official documentation mentions:
The Spring Boot Maven Plugin provides Spring Boot support in Apache Maven. It allows you to package executable jar or war archives, run Spring Boot applications, generate build information and start your Spring Boot application prior to running integration tests.
Since you goal is to create a custom Spring Boot starter, there's no need to use the spring-boot-maven-plugin, so just remove it from your pom.xml and you should be able to package and deploy your jar.

Spring Boot Maven plugin run goal doesn't invoke tests

Following command doesn't run any of my tests :
mvn spring-boot:run
whereas plain old mvn test does.
I have added these annotations to the tests :
#RunWith(SpringRunner.class)
#SpringBootTest
I do not see any relevant information on the plugin documentation pages, either here or here
Spring boot maven plugin
Requires a Maven project to be executed. Requires dependency
resolution of artifacts in scope: test. Since version: 1.1. Binds by
default to the lifecycle phase: validate. Invokes the execution of the
lifecycle phase test-compile prior to executing itself.
More details
Maven lifecycles:
validate compile test ...
More details
To sum up: spring-boot:run only compiles tests and execute maven validate phase. One of the possible solutions to execute tests before start of the application: mvn test spring-boot:run

Groovyc: unable to resolve class geb.spock.GebReportingSpec

I'm using IntelliJ IDEA 14.0.2 Ultimate and created a Maven project.
Here's my pom file: http://pastebin.com/KQ6ARxj3
So I have this Geb Spec class: http://pastebin.com/AerXgCDh
And in my classpath there are all maven dependencies and those are getting downloaded, everything's at his place. Including: Maven: org.gebish:geb-spock:0.10.0
But when I right-click on my module and select "Make Module [Module]" it starts compiling my source files but stops with this error:
C:\Users\...\MyModule\src\test\groovy\MySpockSpec.groovy
Error:(1, 1) Groovyc: unable to resolve class geb.spock.GebReportingSpec
Why can't the groovy compiler resolve this? Maven builds the project successfull and IntelliJ can resolve everything, so what's wrong with the groovy compiler?

Resources