How to implement micronaut dependency in grails gradle? - maven

I'm trying to add micronaut dependency in grails build.gradle. And I found no proper solution. And getting the following error.
build.gradle file
dependencies {
*these are the dependencies I would like to add*
// implementation("io.micronaut.reactor:micronaut-reactor")
// implementation("io.micronaut.reactor:micronaut-reactor-http-client")
// implementation("io.micronaut.security:micronaut-security-jwt")
// implementation("io.micronaut.views:micronaut-views-velocity")
// compileOnly("io.micronaut.security:micronaut-security-annotations")
}
I tried adding mavenCentral() and mavenLocal() in the repositories. And it didn't work. Does anyone know how can I implement micronaut dependencies?
Error
grails:test: Could not find io.micronaut.reactor:micronaut-reactor:.
Required by:
project :

You need to tell Gradle what version of the dependencies to pull down.
repositories {
mavenCentral()
}
dependencies {
implementation platform('io.micronaut:micronaut-bom:3.5.2') // <1>
implementation("io.micronaut.reactor:micronaut-reactor")
implementation("io.micronaut.reactor:micronaut-reactor-http-client")
implementation("io.micronaut.security:micronaut-security-jwt")
implementation("io.micronaut.views:micronaut-views-velocity")
compileOnly("io.micronaut.security:micronaut-security-annotations")
}
The Bill of materials (BOM), which contains all the dependency version numbers for the Micronaut Framework 3.5.2 release.

Related

Gradle repositories conflict forces me to use repository in two places

I have a Gradle multi-project build. Which has a project myApplication that uses a library utils.
The library requires a JasperReports dependency with a custom repository. There is a particular Jasper dependency that produces an error when retrieved from mavenCentral().
If I build utils by itself, it works. Because it fetches the problem jar from the custom repo.
However, if I build myApplication it produces the maven repository error, because it tries to solve the dependency using its mavenCentral() repo.
myApplication/build.gradle.kts:
plugins {
id("application")
}
repositories {
mavenCentral()
}
application {
mainClass.set("com.myapp.SomeMainClass")
}
dependencies {
implementation(project(":utils"))
}
utils/build.gradle.kts:
plugins {
id ("java-library")
}
repositories {
maven {
url = uri("http://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/")
isAllowInsecureProtocol = true
}
mavenCentral()
}
dependencies {
implementation("net.sf.jasperreports:jasperreports:6.18.1")
}
If I include the custom repository in myApplication/build.gradle.kts the project builds ok, but I think adding the custom repo seems like a bad practice, and I think Gradle documentation discourages it.
I think this is actually using a direct dependency in myApplication instead of fixing a transitive dependency. But of that I'm not so sure, and completely lost on how to solve it. I'm really struggling reading the documentation.
Is there a way for me to have Gradle just compile :utils first, and then have :myAplication use the dependency "as is"?

Gradle Dependency Problem when Upgrading to Gradle 6

I have a gradle Project where I have a dependency on "hudson-core 3.3.3"
compile group: 'org.eclipse.hudson', name: 'hudson-core', version: '3.3.3'
This works without a problem when using Gradle 5.6.2
When I upgrade to Gradle 6.0.1 I receive the following error:
Could not resolve org.eclipse.hudson:hudson-remoting:3.0.3.
Required by:
project : > org.eclipse.hudson:hudson-core:3.3.3
project : > org.eclipse.hudson:hudson-core:3.3.3 > org.eclipse.hudson:hudson-cli:3.3.3
> Could not resolve org.eclipse.hudson:hudson-remoting:3.0.3.
> inconsistent module metadata found. Descriptor: org.eclipse.hudson:hudson-remoting:3.0.4-SNAPSHOT Errors: bad version: expected='3.0.3' found='3.0.4-SNAPSHOT'
The Repository is always the same:
repositories {
mavenCentral()
maven {
url 'http://repo.jenkins-ci.org/public/'
}
}
Any Ideas why this error happens?
As said by #ToYonos, the problem is in the dependency itself.
Not perfect solutions, but 2 workarounds can be done as explained in Gradle's documentation (v6.7.1):
Exclude that transitive dependency, for example in the current Gradle versions using implementation instead of compile:
implementation('org.eclipse.hudson:hudson-core:3.3.3') {
exclude group: 'org.eclipse.hudson'
exclude module: 'hudson-remoting'
}
Override that transitive dependency version:
implementation('org.eclipse.hudson:hudson-remoting') {
version {
strictly '3.0.2' // As 3.0.3 is having the issue
}
}
In the pom.xml file of hudson-remoting 3.0.3, the version is <version>3.0.4-SNAPSHOT</version>
The issue is quite clear.
I tried with an old Gradle 4.4.1 and I am having the exact same issue. Likewise with Gradle 5.1.1 and your version, 5.6.2
I'm quite sure that if you clean your artefact cache for Gradle 5.6.2, it won't work anymore.
The error is on the repository side.
Another option is to define a repository that will download only a jar:
repositories {
mavenCentral() {
name = "Download only jar repo"
metadataSources { artifact() }
content {
// Use this repository only for org.eclipse.hudson:hudson-remoting
includeVersion("org.eclipse.hudson", "hudson-remoting", "3.0.3")
}
}
mavenCentral()
}
Also since pom is not downloaded you would have to add hudson-remoting dependencies by hand to build.gradle. But luckily for this particular case hudson-core already contains the only dependency commons-codec:commons-codec:1.4 that hudson-remoting needs, so this is not needed.
Note: the order of repositories is important, although in that case it will work either way. If you don't want to care about the order when using repositories with filter check exclusive content filtering.

Building a Spring-boot project without eclipse gradle

I'm fairly new to gradle and writing a project that I have working in eclipse and was posed with the challenge to write it without eclipse using gradle. I'm finding that even once I add the spring framework configurations to my build file it still can not see what I am importing. I am also using maven so I think it my understanding of gradle changing from a maven project and with SQL. Any thoughts?
Here is my build.gradle:
plugins {
id "org.springframework.boot" version "1.5.9.RELEASE"
id "io.spring.dependency-management" version "1.0.4.RELEASE"
}
apply plugin: 'java'
repositories {
jcenter()
mavenCentral()
}
// spring dependency management plugin configuration
dependencyManagement {
imports {
// select versions based on this BOM
mavenBom 'io.spring.platform:platform-bom:1.1.1.RELEASE'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework:spring-jdbc")
compile('mysql:mysql-connector-java:5.1.37')
}
You need to add spring boot dependencies.
like:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
}
See the Spring documentation:
https://spring.io/guides/gs/spring-boot/#scratch

Gradle with a local pom dependency picks up wrong version

My build.gradle references a local maven pom. I have enabled the mavenLocal() repository and have added the jar as a compile time dependency (eg. my-local-lib, as shown below).
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile (group: 'com.company', name: 'my-local-lib', version: '1.0-SNAPSHOT')
}
Gradle indeed picks it up and adds it as a dependency. My-local-lib, however, is itself dependent on another library as specified in its pom.xml, but gradle fails to pick up the correct version specified in the pom.xml, and instead chooses a much earlier version. This particular jar dependency is not a dependency on any other library.
Is this a known issue? Could it be due to my-local-lib being a SNAPSHOT version? Is there a way that I can enforce gradle to respect the versions specified in the libraries?
Try to add the following piece of code:
configurations.all {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
}
}
to build.gradle script.

Is it possible to restrict a gradle repository to a particular configuration?

I want to tie gradle repositories to specific configurations in my build.gradle file, e.g.:
repositories {
testCompile {
mavenCentral()
}
compile {
maven { url 'https://vetted-repo.example.com' }
}
}
I can't find a simple way to do this from the gradle documentation. Do I need to write my own plugin?
As of Gradle 5.1 this is now possible, from the release notes:
It is now possible to match repositories to dependencies, so that
Gradle doesn't search for a dependency in a repository if it's never
going to be found there.
Example:
repositories {
maven {
url "https://repo.mycompany.com"
content {
includeGroupByRegex "com\\.mycompany.*"
}
}
}
For the specific requirement of restricting a repository to a specific configuration such as compile, you could use the onlyForConfigurations property:
repositories {
maven {
url "https://vetted-repo.example.com"
content {
onlyForConfigurations "compile"
}
}
}
This is not supported by gradle at the moment. When resolving dependencies, gradle tries al listed repositories (from top to bottom) to resolve a dependency. Once the dependency is found it stops looking for it in other repositories
It is now possible to declare a repository filter in gradle. see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html#declaring_a_repository_filter this does exactly what you need here.

Resources