I am trying to understand Gradle.I got this in my code
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.9.0'
It works.
I wanted to understand the concepts.
Remote dependencies in Gradle follow the same format as Maven. Dependencies are structured as follows
compile 'group:name:version'
or this alternative syntax:
compile group: 'xxx', name: 'xxxxx', version: 'xxxx'
The same syntax is valid also for tests.
dependencies {
testCompile "org.mockito:mockito-core:2.9.0"
}
or
dependencies {
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.9.0'
}
Related
I am working on the following Nifi controller service bundle:
nifi-controllers-bundle
nifi-controllers
nifi-controllers-api
nifi-controllers-nar
nifi-controllers-api-nar
I have a custom controller service created(StandardMyService) that extends DBCPConnectionPool in the nifi-controllers module and when I try to use it in UI I get the following exception in logs: ERROR [NiFi Web Server-36] o.a.nifi.controller.ExtensionBuilder Could not create Controller Service of type com.xxx.yyy.StandardMyService for ID 812de259-0181-1000-3536-a06e3ae9f2ed due to: Controller Service com.xxx.yyy.StandardMyService is bundled with its supporting APIs org.apache.nifi.dbcp.DBCPService. The service APIs should not be bundled with the implementations.; creating "Ghost" implementation and this one in UI: 'Missing Controller Service' validated angainst 'Any property' is invalid because controller service is of type com.xxx.yyy.StandardMyService but this is not a valid Reporting Task Type
I do not think there is something wrong with the way I have implemented the StandardMyService class because I have tested it in a nifi controller service maven archetype and it works.
My nifi-controllers build.gradle looks like this:
dependencies {
implementation group: 'com.oracle.ojdbc', name: 'ojdbc8', version: '19.3.0.0'
implementation group: 'org.apache.nifi', name: 'nifi-nar-bundles', version: '1.12.0', ext: 'pom'
compileOnly group: 'org.apache.nifi', name: 'nifi-api', version: '1.16.1'
implementation group: 'org.apache.nifi', name: 'nifi-utils', version: '1.16.1'
compileOnly group: 'org.apache.nifi', name: 'nifi-dbcp-service-api', version: '1.16.1'
implementation group: 'org.apache.nifi', name: 'nifi-dbcp-service-nar', version: '1.16.1'
compileOnly group: 'org.apache.nifi', name: 'nifi-dbcp-service', version: '1.16.1'
testImplementation group: 'org.apache.nifi', name: 'nifi-mock', version: '1.16.1'
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.36'
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
implementation group: 'com.fasterxml', name: 'aalto-xml', version: '1.3.2'
}
tasks.named('test') {
useJUnitPlatform()
}
I got it to work by extending AbstractControllerService instead of DBCPConnectionPool, therefore not needing org.apache.nifi.dbcp.DBCPService anymore.
LE: Having the project built with gradle, there is no
<type>nar</type>
for nifi-standard-services-api-nar that puts this dependency in the MANIFEST file of the nar archive of processors-nar. When I added manually these lines in MANIFEST file, everything worked:
Nar-Dependency-Id: nifi-standard-services-api-nar
Nar-Dependency-Group: org.apache.nifi
and the only dependency needed in the project is nifi-dbcp-service-api in processors build.gradle.
I am using grpc springboot. I can download all dependencies apart from 'net.devh:grpc-server-spring-boot-starter:2.12.0.RELEASE'.
Due to the I can't use annotation #GrpcService
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'io.grpc:grpc-netty-shaded:1.37.0'
implementation 'io.grpc:grpc-protobuf:1.37.0'
implementation 'io.grpc:grpc-stub:1.37.0'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
implementation 'org.springframework.boot:spring-boot-starter:2.4.5'
implementation 'net.devh:grpc-server-spring-boot-starter:2.12.0.RELEASE'
compileOnly 'jakarta.annotation:jakarta.annotation-api:1.3.5'
}
Any help much appreciated
Just try the install dependencies and reimport them.
If it doesn't work, close the IDE and open it again.
Unable to use Spring's reactive WebClient in a Spring boot based Web Application which runs on Tomcat. Application startup itself is failing due to unresolved dependencies.
I looked at https://github.com/spring-projects/spring-boot/issues/9690 but unfortunately thats not an option for me as I cannot set the WebApplication type to None
My gradle file:
dependencies {
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa') {
exclude(module: 'tomcat-juli')
}
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
compile group: 'org.springframework.session', name: 'spring-session'
compile group: 'org.hibernate', name: 'hibernate-java8'
compile group: 'org.hibernate', name: 'hibernate-validator', version: '5.2.4.Final'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-guava'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310'
compile group: 'com.google.guava', name: 'guava'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'
compile group: 'org.postgresql', name: 'postgresql'
compile group: 'io.jsonwebtoken', name: 'jjwt', version:'0.9.0'
compile group: 'com.nimbusds', name: 'nimbus-jose-jwt', version:'5.12'
// Spring managed dependency is not working, so resorted to using specific version
// compile('org.springframework.boot:spring-boot-starter-webflux')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: '2.1.4.RELEASE'
/*
compile group: 'org.springframework', name: 'spring-web-reactive', version: '5.0.0.M1'
compile group: 'org.springframework', name: 'spring-web', version: '5.1.6.RELEASE'
*/
implementation 'com.auth0:jwks-rsa:0.7.0
}
bootRepackage {
enabled = false
}
Error:
Caused by: java.lang.NoClassDefFoundError: org/springframework/http/client/reactive/ClientHttpConnector
at org.springframework.web.reactive.function.client.WebClient.create(WebClient.java:144)
I then tried adding,
compile group: 'org.springframework', name: 'spring-web-reactive', version: '5.0.0.M1'
Which then complained about something else, which made me add
compile group: 'org.springframework', name: 'spring-web', version: '5.1.6.RELEASE'
But then another error shows up while starting my application, which makes me think there is some other problem.
To be precise,I simply want to call a MicroService using Reactive WebClient from within another MicroService (which is Spring Boot based Web Application).
Using RestTemplate works fine but I just wanted to try the reactive WebClient and stuck with error.
Due to the way we host our dependencies, managed dependencies are not working. Our dependency server is unable to resolve them. That's the reason for having specific version of spring boot dependencies
org.springframework.http.client.reactive.ClientHttpConnector is part of the spring-web jar so it should be available if use use spring-boot-starter-webflux or spring-boot-starter-web. If you're writing a traditional servlet based application then you should be using spring-boot-starter-web.
Check the output of gradle dependencies to ensure that you have a spring-web jar. If you do, the chances are it's somehow been corrupted and you should clear your gradle cache.
I'd also recommend that you use Spring Boot's managed dependencies rather than specifify version numbers on each dependency. This will ensure that you get versions that are known to work well together.
I have a Spring Boot web application which uses Gradle and NPM. I created a package.json file and npm install works fine. But I'd like to be able to run npm install automatically when I run gradle build. Here's my build file:
plugins {
id 'org.springframework.boot' version '1.5.10.RELEASE'
id 'java'
id 'war'
id "org.ysb33r.nodejs.base" version "0.1"
id "org.ysb33r.nodejs.npm" version "0.1"
}
group 'com.Blahblah'
version '1.0-SNAPSHOT'
war {
baseName = 'Blahblah'
version = '0.0.1'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
maven { url "http://repo.spring.io/libs-snapshot" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.3'
compile group: 'com.cloudinary', name: 'cloudinary-core', version: '1.17.0'
compile group: 'com.cloudinary', name: 'cloudinary-http44', version: '1.17.0'
compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.5.10.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jersey', version: '1.5.10.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '1.5.10.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.10.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '1.5.10.RELEASE'
classpath "gradle.plugin.org.ysb33r.gradle:nodejs-gradle-plugin:0.1"
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '1.5.10.RELEASE'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
apply plugin: "org.ysb33r.nodejs.base"
apply plugin: "org.ysb33r.nodejs.npm"
I added the ysb33r parts in plugins, dependencies and apply plugin sections, but now I get an error at the line:
classpath "gradle.plugin.org.ysb33r.gradle:nodejs-gradle-plugin:0.1"
It says:
A problem occurred evaluating root project 'Blahblah'.
> Could not find method classpath() for arguments [gradle.plugin.org.ysb33r.gradle:nodejs-gradle-plugin:0.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Before I added the ysb33r lines, the build worked fine. What could be the problem? And when the problem is solved, how should I proceed in order to run npm install automatically?
Thanks.
A couple of issues:
Exec.commandLine is a String array
Your println is happening in the configuration phase, put it in a doLast block so it executes in the execution phase
Eg:
task npmInstall(type: Exec) {
commandLine 'npm install'.split(' ')
doLast {
println 'DONE!'
}
}
Rather than calling npm via Exec task, you should consider one of the gradle/nodejs plugins. Most of these are able to use an embedded nodejs version, downloaded from a repository, to execute nodejs commands rather than require a nodejs installation on the machine
See: https://plugins.gradle.org/search?term=nodejs
Eg: http://ysb33rorg.gitlab.io/nodejs-gradle-plugin/
We have the following configuration in a project...
configurations {
//compile.exclude module: 'commons'
//all*.exclude group: 'org.gradle.test.excludes', module: 'reports'
all*.exclude module: 'log4j'
}
dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.6'
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.6.6'
compile group: 'com.google.inject', name: 'guice', version: '3.0'
compile group: 'com.google.protobuf',name: 'protobuf-java', version: '2.4.1'
//compile group: 'org.asteriskjava',name: 'asterisk-java', version: '1.0.0.M3'
//to be erased soon
compile group: 'commons-configuration',name:'commons-configuration',version: '1.8'
//compile group: 'org.bouncycastle', name: 'bcpg-jdk16', version: '1.46'
compile project(':sdi-master')
compile project(':sdi-webserver')
}
unfortunately, the project sdi-webserver has it's own log4j brought in from a filetree like so
project(':sdi-webserver') {
project.ext.genLibDir = file('lib')
dependencies {
compile project(':sdi-master')
compile fileTree(dir: '../webserver/lib', include: '*.jar')
compile fileTree(dir: '../webserver/play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: '../webserver/play-1.2.4/framework', include: 'play-*.jar')
}
How do we exclude this jar so it is not part of the dependencies. The above excludes that we have only works for repositories and transitive dependencies and doesn't work for fileTree, but we still need to somehow exclude the jar file as we want eclipse task building correct .classpath, we want configurations.compile having accurate info for copying jars, etc. etc.
thanks,
Dean
Simply use an exclude on fileTree. Syntax is the same as for include.