Gradle AspectJ plugin issue - gradle

I am facing a major issue with my Spring application since I migrated from Maven to Gradle: aspectj no longer works.
For instance classes annotated with #Configurable (which rely on aspectj) don't get their dependencies injected.
In order to replace the aspectj-maven-plugin, I tried using this plugin: from spring security code base but it seems it is not compatible with Gradle 2.1...
I also tried applying the solution described here: http://architects.dzone.com/articles/working-gradle-spring-aspects to no avail.
I am just curious to know how people who use Gradle + Spring manage to leverage aspectj...
Can anyone please kindly advise?

Related

How to discover which spring jar includes a spring package and class?

I am upgrading the libraries on a system and am implementing spring boot. But, there are some dependencies that have to be added over and above the spring boot starters, and some of these are Spring classes.
How can I tell which library a package and class is coming from? The documentation for the class does not seem to provide this...
If i'm understanding correctly, what i do is looking for Compile Dependencies in the maven repos.

Making a spring boot fat jar file with gradle WITHOUT a spring boot gradle plug-in (no access to bootJar)

I have a spring-boot application in which I loaded all the necessary (or so I believe) dependencies to run without using spring-boot initializer or the spring-boot gradle plug-in. These tools are not available for me at my work. I can run the application through intellij without issues, but when attempting to run a fat jar, I am met with
No auto configuration classes found in META-INF/spring.factories.
Now the spring.factory files ARE located inside the fat jar (there are multiples of them) and they are inside the meta-inf directory.
Spring boot has so much automated functionality, I am not sure where to begin. There are a lot of similar posts and everyone just tells people to use the spring-boot gradle plugin bootJar task but as I said these are not available to me. I need to get it running without those tools,
if anyone has insight into what the issue may be or how to resolve it, any help is appreciated. I will try to add more details later.
I am using spring-boot v. 2.1.1 and spring 5.1.4

spring boot compatibility issue with starter-web

I have just started working on a spring boot project and I am using stater web as one of its dependency, I used spring.io to create my project from scratch and from there itself I got
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
Now the problem I faced is my static content is not loading properly. I can see the static URL on browser's dev-tools with 200 OK message(which probably means a successful response of a get request) but still, the styles are not there as my CSS is not loading.
but if I use spring boot version 2.0.4 then everything works fine.
I went through release notes for spring boot version '2.1.6 RELEASE' but couldn't find anything except this
Auto-Configuration Exclusion
Exclusions are now applied consistently rather than only being applied locally. This applies to any exclusion defined on #EnableAutoConfiguration, #SpringBootApplication, #ImportAutoConfiguration or the spring.autoconfigure.exclude property.
which went over my head.
My question is if someone uses spring.io to create a project from scratch and in return gets all the dependencies compatible version from spring-boot starter parent and still the project for some reason like one mentioned above doesn't work then where should one go to find out what is the problem rather then changing version's.

Gradle 5 JUnit BOM and Spring Boot Incorrect Versions

I am using Gradle 5's BOM (Bill of Materials) feature. This is how I describe it for my JUnit 5 dependencies:
testImplementation(enforcedPlatform("org.junit:junit-bom:5.4.0")) // JUnit 5 BOM
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.junit.jupiter:junit-jupiter-params")
My assumption is that providing the BOM will resolve the versions of the dependencies to 5.4.0. However, they get resolved to 5.1.1. I am not sure why. (I also request enforcedPlatform() to lock the specified version)
Inspecting JUnit 5's BOM we see that all org.junit.jupiter dependencies are listed with version 5.4.0 (resolving to 5.1.1 in the project) and all org.junit.platform dependencies are listed with version 1.4.0 which resolve correctly in the project.
I am not sure what I am missing and was hoping to get some help here. Thanks!
EDIT:
I used Sormuras response and moved all BOMs at the top of the dependencies {} block but was still not getting version 5.4.0. Then I suspected it might be coming from the Gradle Spring Dependency Management plugin that I use, so when I commented it out, I got version JUnit 5.4.0. How do I disable JUnit coming from the Gradle Spring Dependency Management plugin?
FINALLY:
I decided to use the Spring Boot Dependencies BOM directly and remove the Gradle plugin:
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE"))
I imagine the plugin was created for those version of Gradle before Gradle 5 where you couldn't use a BOM file. Now with the BOM support I can directly include it. This way my version of JUnit is as I have specified it in the enforcedPlatform() block.
I accepted Sam Brannen's answer below because he explains well how the issue occurs and what solves it and I think it's relevant for those who use older versions of Gradle.
How do I disable JUnit coming from the Gradle Spring Dependency Management plugin?
For starters, if you are using the dependency management plugin from Spring, you should not be importing the junit-bom since that results in duplicate (and potentially conflicting) management of those dependencies.
Aside from that, whenever you use the dependency management plugin from Spring and want to override a managed version, you have to do it by overriding the exact name of the version defined in the BOM used by the plugin.
This is documented in Spring Boot for Gradle and for Maven.
For Spring Boot the name of the JUnit Jupiter version is "junit-jupiter.version". You can find the names of all managed versions for Spring Boot 2.1.2 here.
So, in Gradle you would override it as follows.
ext['junit-jupiter.version'] = '5.4.0'.
You can see that I have done exactly that here.
With Maven you would override it as follows.
<properties>
<junit-jupiter.version>5.4.0</junit-jupiter.version>
</properties>
Further background information here: https://docs.spring.io/platform/docs/current/reference/html/getting-started-overriding-versions.html
JUnit 5.4.0 simplified its artifacts, and now delivered a single artifact for Jupiter - org.junit:junit-jupiter. I.e., you should simplify your Gradle file too:
testImplementation(enforcedPlatform("org.junit:junit-bom:5.4.0")) // JUnit 5 BOM
testImplementation("org.junit.jupiter:junit-jupiter")
Ensure to include JUnit's BOM before other BOMs that also refer to JUnit. First BOM wins and locks version of all later artifacts.
See this issue for a similar setup using Maven and Spring Boot: https://github.com/sormuras/junit-platform-maven-plugin/issues/29#issuecomment-456958188

Configuring Spring security with spring boot on already created project, IntelliJ

I have previous experience in Spring MVC but I am new to Spring Boot.
I am Using IntelliJ for the first time.
What I noticed is that when you create a Spring boot project with security dependencies added during the time of creation, Then the IDE creates the project already configured With Basic Authentication whereas if I add dependencies to pom.xml after creation, then the application won't get configured with basic authentication automatically.
Can anyone explain this behavior of IntelliJ and can anyone help me with steps for configuring the pre-created project with Basic Authentication?
IntelliJ is using
https://start.spring.io/
to initialise your project. After the project is initialised, the IDE doesn't modify your code in any way. That is the normal behaviour and it is not Spring Boot related.
NOTE: The dependency that you add in your pom.xml is just pulling down that dependency, but if you need to use it you do the code yourself. (More information about Maven: https://en.wikipedia.org/wiki/Apache_Maven)

Resources