Could not find method provided() for arguments [{group=javax.servlet, name=javax.servlet-api, version=3.1.0}] - gradle

I am getting the following error:
Could not find method provided() for arguments [{group=javax.servlet,
name=javax.servlet-api, version=3.1.0}]
I have tried several different ways and found people with similar issues but with no avail. I added the below dependency but
repositories {
mavenLocal()
mavenCentral()
maven { url "http://repo.maven.apache.org/maven2" }
provided group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
If I remove the javax.servlet I am back to the orginal error:
Could not find method providedCompile() for arguments [{group=javax.servlet, name=javax.servlet-api, version=3.1.0}]
update 1:
new error after adding:
dependencies {
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'
}
error
> Could not find javax.servlet:servlet-api:3.1.0.
Searched in the following locations:
http://repo.maven.apache.org/maven2/javax/servlet/servlet-api/3.1.0/servlet-api-3.1.0.pom
http://repo.maven.apache.org/maven2/javax/servlet/servlet-api/3.1.0/servlet-api-3.1.0.jar
Required by:
project :
UPDATE:
I added:
allProjects {
apply plugin: 'maven'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
jcenter()
mavenCentral()
version = '0.0.1-SNAPSHOT'
group = 'com.lidl.digital.ecom.ratings'
dependencies {
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'
}
}
And now the error is:
What went wrong: A problem occurred evaluating root project 'product-rating-parent'.
Could not set unknown property 'sourceCompatibility' for object of type org.gradle.api.internal.initialization.DefaultScriptHandler.
I have seen this error prior to fixing this posted question so I am not sure if it is fixed. When I hover over anything in the gradle file it says cannot resolve 'whatever I hover over'

It seems, that you have added your dependency in the wrong place. Dependecies are declared within dependencies block as follows
dependencies {
provided group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
}
But in your case it's declared within repositories.

There is a difference between what you report as added and your exception:
dependencies {
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'
}
The above is correct, and exists in Maven Central.
However, your error:
Could not find javax.servlet:servlet-api:3.1.0.
Searched in the following locations:
http://repo.maven.apache.org/maven2/javax/servlet/servlet-api/3.1.0/servlet-api-3.1.0.pom
http://repo.maven.apache.org/maven2/javax/servlet/servlet-api/3.1.0/servlet-api-3.1.0.jar
Required by:
project :
It clearly indicates a typo somewhere in the project where the dependency module name is missing the javax. part in front of servlet-api.
So you must have somewhere code like:
dependencies {
compileOnly group: 'javax.servlet', name: 'servlet-api', version:'3.1.0'
}
Notice the missing javax. in the name attribute.

Related

With the new update of JDA 4.2.0 the new built JAR file on the VPS returns NoClassDefFoundError

With the new update of JDA 4.2.0 trying to run the jar file on the VPS fails.
I have tried various options, such as
creating a fat jar
searching for other similar issues
source 1
source 2
Yet none of these options seemed to work, since the VPS console output stays unchanged:
Error: Could not find or load main class ...
Caused by: java.lang.NoClassDefFoundError: net/dv8tion/jda/api/hooks/ListenerAdapter
So my current question is, what should my gradle.build look like, or is this a problem of the VPS not refreshing correctly? Or perhaps another problem I'm not aware of.
As for what my gradle.build looks like:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
group '...'
version '2.0-SNAPSHOT'
repositories {
mavenCentral()
jcenter(
)
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'net.dv8tion:JDA:4.2.0_168'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.20'
compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'
compile 'com.vdurmont:emoji-java:5.1.1'
}
jar {
manifest {
attributes(
'Main-Class': '...'
)
}
}
NOTE: In the previous snapshot of 1.0-SNAPSHOT this following gradle.build worked to start up the project:
plugins {
id 'java'
id 'application'
}
group '...'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
jcenter()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'net.dv8tion:JDA:3.5.0_329'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.20'
compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'
compile 'com.vdurmont:emoji-java:5.1.1'
}
You can use this build.gradle to build a working shadow jar:
plugins {
id 'application' // this allows you to set a mainClassName
id 'com.github.johnrengelman.shadow' version '6.0.0' // this adds the shadowJar task
}
group '...'
version '2.0-SNAPSHOT'
mainClassName = 'your main class goes here' // this sets the main class property in your manifest automatically
repositories {
jcenter() // jcenter is a superset of mavenCentral
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'net.dv8tion:JDA:4.2.0_191'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.20'
compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'
compile 'com.vdurmont:emoji-java:5.1.1'
}
Run the shadowJar gradle task to compile your jar file. This will then be placed inside build/libs and has the format [name]-all.jar. Do not forget to replace the mainClassName with the fully qualified name of your main class.

Why does my Gradle build fail with a "Plugin [id: 'org.flywaydb.enterprise.flyway', version: '6.5.0'] was not found" error?

When I run gradle clean build I get the build error message:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\meno.varghese\git\imc-modulemanager-poc\imc-poc\build.gradle' line: 5
* What went wrong:
Plugin [id: 'org.flywaydb.enterprise.flyway', version: '6.5.0'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.flywaydb.enterprise.flyway:org.flywaydb.enterprise.flyway.gradle.plugin:6.5.0')
Searched in the following repositories:
MavenLocal(file:/C:/Users/meno.varghese/.m2/repository)
Gradle Central Plugin Repository
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
I don't understand why the flyway plugin cannot be found. How can I fix it?
Here's my build.gradle file:
plugins {
id 'org.springframework.boot' version '2.0.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id "org.flywaydb.enterprise.flyway" version '6.5.0'
}
apply plugin: "eclipse"
group = 'com.imc.poc'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.20'
compile group: 'org.javassist', name: 'javassist', version: '3.27.0-GA'
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.808'
}
flyway {
//url = 'jdbc:mysql://localhost:3306/imc_poc?user=root&password=password'
// driver = 'org.postgresql.Driver'
url = 'jdbc:mysql://imc-modulemanager.cwouijqzv1sr.ap-south-1.rds.amazonaws.com:3306'
user = 'admin'
password = 'Indegene12345'
schemas=['moduledb']
}
With reference to the official Flyway Gradle Plugin documentation page
plugins {
id "org.flywaydb.flyway.enterprise" version "6.5.0"
}
Your plugin declaration in your gradle.build
id "org.flywaydb.enterprise.flyway" version '6.5.0'
is simply wrong, and thus cannot be found.

How can I publish many dependant subprojects in a certain order with gradle?

I'm trying to publish two subprojects with gradle. I have two subprojects: SubprojectA is dependant on SubprojectB. I want to publish them both using maven-publish. I have this in build.gradle:
plugins {
id 'java'
id 'maven-publish'
}
publishing {
publications {
SubprojectA(MavenPublication) {
println(project(':subprojectA').tasks)
groupId group
artifactId 'subjprojectA'
version version
artifact project(':subprojectA').tasks.getByName('jar')
}
SubprojectB(MavenPublication) {
groupId group
artifactId 'subjprojectB'
version version
artifact project(':subjprojectB').tasks.getByName('jar')
}
}
repositories {
maven {
url "http://some-url"
}
}
}
Gradle tries to publish them in alphabetical order: Since subprojectA depends on subprojectB, it doesn't work because subprojectB hasn't been published yet. If I rename subprojectA to ZSubprojectA, like this:
ZSubprojectA(MavenPublication) {
println(project(':subprojectA').tasks)
groupId group
artifactId 'subprojectA'
version version
artifact project(':subprojectA').tasks.getByName('jar')
}
then it works, but I don't like this solution. I've tried something like this:
project(':subprojectA') {
publish.dependsOn(":subprojectB:build")
}
but it doesn't work, and :subprojectB:publish doesn't exist.
I've been able to solve it. This was the problem:
Both subprojects had their respective build.gradle files. In subprojectA's build.gradle there was something like this:
plugins {
id 'java'
}
sourceCompatibility = 1.8
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation group: 'com.neovisionaries', name: 'nv-i18n', version: '1.22'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
implementation group: 'com.myorg.something', name: 'subprojectB', version: '1.0.0-SNAPSHOT'
}
Therefore it was trying to get subprojectB from my organization private repository, and I should have done something like this:
compile project(":subprojectB")
I should have include both build.gradle files in my question. But the problem is solved.

Spring-Boot html in /templates don't render from command line

I have read several online posts about this issue, but for some reason none of those helped me solve this. I looked at the spring-boot examples and I don't think I am doing much different than those.
I am using Spring-boot 1.2.1, Thymeleaf, embedded tomcat without issue in IntelliJ. However, when I do a "gradle clean build", move the jar file, and an application.properties file to a deploy directory. I then start on the command with:
java -jar edm-0.1.0.jar
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/loginPage", template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:245)
I am letting spring-boot configure my site for the most part. I am using the recommended directory structure:
I can hit the index page, and the REST calls seem to work just fine.
UPDATE based upon feedback:
I don't know if this is a broken jar issue, but when I extract it the structure and files appear correct. I can run "gradle bootRun" from the top of my project structure just fine. But if I deploy the jar file and run it, I get an error:
Task 'bootRun' not found in root project 'edm'
Here is my build.gradle file in case there might be an issue in it:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'maven'
idea {
project {
//if you want to set specific jdk and language level
jdkName = '1.8'
languageLevel = '1.8'
}
}
jacoco {
toolVersion = "0.7.0.201403182114"
}
project.ext {
springBootVersion = '1.2.1.RELEASE'
}
configurations {
querydslapt
}
buildscript {
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
}
}
jar {
baseName = 'edm'
version = '0.1.0'
}
dependencies {
querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier: 'apt-one-jar', transitive: false
compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion")
compile("org.springframework.security:spring-security-web:4.0.0.M1")
compile("org.springframework.security:spring-security-config:4.0.0.M1")
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.1.RELEASE')
compile('com.android.tools.build:gradle:1.0.1')
compile("org.hibernate:hibernate-core:4.3.4.Final")
compile("org.hibernate:hibernate-entitymanager:4.3.4.Final")
compile("org.hibernate:hibernate-validator")
compile("org.apache.velocity:velocity:1.7")
compile('javax.mail:mail:1.4.1')
compile("org.springframework:spring-context-support")
compile("com.h2database:h2:1.3.172")
compile("joda-time:joda-time:2.3")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.5.0")
compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")
compile('org.codehaus.groovy:groovy-all:2.2.1')
compile('org.jadira.usertype:usertype.jodatime:2.0.1')
compile("postgresql:postgresql:9.1-901.jdbc4")
testCompile('org.spockframework:spock-core:1.0-groovy-2.0-SNAPSHOT') {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile('org.spockframework:spock-spring:1.0-groovy-2.0-SNAPSHOT') {
exclude group: 'org.spockframework', module: 'spock-core'
exclude group: 'org.spockframework', module: 'spring-beans'
exclude group: 'org.spockframework', module: 'spring-test'
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')
testCompile("junit:junit")
// for the anontation processor
querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier: 'apt-one-jar', transitive: false
// for compiling
compile("com.mysema.querydsl:querydsl-jpa:3.3.3")
compile("com.mysema.querydsl:querydsl-apt:3.3.3")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
project.configurations {
providedRuntime
}
project.bootRepackage {
enabled = true
}
I also tried adding some thymeleaf configuration (even though I am not explicitly using Thymeleaf) to my application.properties file:
liquibase.changeLog=classpath:/db/changelog/db.changelog-master.xml
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.check-template-location=true
So I guess my question is, why does running the "java -jar" not let me view the webpages?
It turns out that my REST controllers were proceeded by "/" so login page became "//loginPage" and that was causing the problem. I found the answer here but it took me a while to realize that was the issue. Hopefully this answer will help out someone in the future as it as a bear to figure out.

How to give dependecies in multiproject in Gradle and what is the structure?

I have a multi project to be built using Gradle which has a java Project and it'll be dependancy for web Project. When I build with eclipse i have given depencies of javaProj and webProj to webprojectEAR and it works(after deployed).
.ear file needs to be created using single build run whcih has the following content.
- lib
javaProj.jar
- META-INF
- webProj.war
my project structure as follows
- javaProj
build.gradle
- webProj
build.gradle
- webProjEAR
build.gradle
- settings.gradle
I'm trying to run the webProjEAR/build.gradle file and given as dependency as follows in it.
project(':webProjEAR') {
dependencies {
compile project(':javaProj')
compile project(':webProj')
}
}
it failed with error "Could not resolve all dependencies for configuration 'webProjEAR:testRuntime' .when I run build files separatly I am able to create jar and war files.
Please can anyone help me how dependencies should be mentioned in the build files. And, where are the madatory locations to have a build.gradle file.
=== More Information added to the original question from here ===
My build files are as below. I have made the changes Igor Popov had mentioned.
// javaProj/build.gradle
apply plugin: 'java'
repositories {
flatDir { dirs "../local-repo" }
}
sourceSets {
main {
java.srcDir "$projectDir/src"
resources.srcDir "$projectDir/XML"
}
}
jar {
from ('classes/com/nyl/xsl') {
into 'com/nyl/xsl'
}
}
dependencies {
compile group: 'slf4j-api' , name: 'slf4j-api' , version: '1.5.6'
compile group: 'slf4j-jdk14' , name: 'slf4j-jdk14' , version: '1.5.6'
compile group: 'com.ibm.xml.thinclient_1.0.0' , name: 'com.ibm.xml.thinclient_1.0.0' , version: '1.0.0'
compile group: 'junit', name: 'junit', version: '4.11'
compile group: 'saxon9' , name: 'saxon9'
compile group: 'saxon9-dom' , name: 'saxon9-dom'
compile group: 'xmlunit' , name: 'xmlunit' , version: '1.4'
}
==============================================
// webProj/build.gradle
apply plugin: 'war'
repositories {
flatDir { dirs "../local-repo" }
}
webAppDirName = 'WebContent'
dependencies {
providedCompile group: 'com.ibm.xml' , name: 'com.ibm.xml'
providedCompile group: 'com.ibm.ws.prereq.xdi2' , name: 'com.ibm.ws.prereq.xdi2'
providedCompile group: 'com.ibm.ws.xml.admin.metadata' , name: 'com.ibm.ws.xml.admin.metadata'
providedCompile group: 'guava' , name: 'guava' , version: '11.0.2'
providedCompile group: 'j2ee' , name: 'j2ee'
providedCompile group: 'slf4j-api' , name: 'slf4j-api' , version: '1.5.6'
providedCompile group: 'slf4j-log4j12' , name: 'slf4j-log4j12' , version: '1.5.6'
}
====================================================
// webProjEAR/build.gradle
apply plugin: 'java'
apply plugin: 'ear'
repositories {
flatDir { dirs "../local-repo" }
}
dependencies {
compile project(':javaProj')
compile project(':webProj')
}
ear {
appDirName 'src/main/app'
libDirName 'APP-INF/lib'
from ('../javaProj/build/libs') {
into 'lib'
}
from ('../webProj/build/libs') {
into '/'
}
}
I would like to know what should contain in the roojProj/build.gradle file. Also like to know anything needs to be changed in the above files. Thanks
The overall structure should be something like:
rootProj
javaProj
build.gradle
webProj
build.gradle
webProjEAR
build.gradle
settings.gradle
build.gradle
The settings.gradle file should contain:
include 'javaProj', 'webProj', 'webProjEAR'
For the webProjEAR/build.gradle you can remove the project(':webProjEAR'). So it should look like:
dependencies {
compile project(':javaProj')
compile project(':webProj')
}
To fix the error you get, you should also post all your dependencies for webProjEAR (if you have others that you didn't include).

Resources