I have added web dependency by editing build.gradle file and adding line below in my Spring Eclipse Java project.
dependencies {
...
implementation 'org.springframework.boot:spring-boot-starter-web'
...
}
But project complains The import org.springframework.web cannot be resolved. How to tell Spring Tool Suite 4 project update this library?
UPD
My whole build.gradle :
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'war'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '15'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
UPD 2
I have another project that was generated with web module from very beginning. I looked in project properties in both of them and found that current project don't have Web App Libraries :
Current project:
Should I ask gradle somehow update Spring Tool Suite project with required library?
UPD 3 Project file structure:
drwxrwxr-x 8 a a 4096 Oct 4 07:39 .
drwxrwxr-x 6 a a 4096 Oct 4 08:27 ..
drwxrwxr-x 5 a a 4096 Oct 1 08:18 bin
drwxrwxr-x 9 a a 4096 Oct 4 07:39 build
-rw-r--r-- 1 a a 599 Oct 4 05:32 build.gradle
-rw-rw-r-- 1 a a 1102 Oct 1 08:18 .classpath
-rw-r--r-- 1 a a 397 Oct 1 07:54 .gitignore
drwxrwxr-x 7 a a 4096 Oct 1 07:56 .gradle
drwxrwxr-x 3 a a 4096 Oct 1 07:54 gradle
-rwxr-xr-x 1 a a 5766 Oct 1 07:54 gradlew
-rw-r--r-- 1 a a 2763 Oct 1 07:54 gradlew.bat
-rw-r--r-- 1 a a 590 Oct 1 07:54 HELP.md
-rw-rw-r-- 1 a a 741 Oct 1 08:18 .project
drwxrwxr-x 2 a a 4096 Oct 1 08:18 .settings
-rw-r--r-- 1 a a 26 Oct 1 07:54 settings.gradle
drwxrwxr-x 4 a a 4096 Oct 1 07:54 src
did you also add
repositories {
mavenCentral()
}
To your gradle build? The maven import needs to resolved from somewhere, maven central is a good place.
According to Spring you also need to use the spring plugin
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
At the top of your build gradle
Related
with Gradle 6.7 and spotbugs toolVersion 4.1.4. I am getting following error.
looks like I have to exclude some unwanted version, any help?
stack trace
Caused by: org.gradle.api.tasks.TaskInstantiationException: Could not create task of type 'SpotBugsTask'.
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:97)
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:84)
at org.gradle.util.GUtil.uncheckedCall(GUtil.java:442)
at org.gradle.api.internal.AbstractTask.injectIntoNewInstance(AbstractTask.java:201)
at org.gradle.api.internal.project.taskfactory.TaskFactory.create(TaskFactory.java:84)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.create(AnnotationProcessingTaskFactory.java:48)
at org.gradle.api.internal.tasks.DefaultTaskContainer.createTask(DefaultTaskContainer.java:326)
at org.gradle.api.internal.tasks.DefaultTaskContainer.access$200(DefaultTaskContainer.java:77)
at org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreatingProvider.createDomainObject(DefaultTaskContainer.java:701)
at org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreatingProvider.createDomainObject(DefaultTaskContainer.java:658)
at org.gradle.api.internal.DefaultNamedDomainObjectCollection$AbstractDomainObjectCreatingProvider.tryCreate(DefaultNamedDomainObjectCollection.java:941)
... 180 more
Caused by: java.lang.NoSuchMethodError: 'java.lang.Object org.gradle.util.DeprecationLogger.whileDisabled(org.gradle.internal.Factory)'
at com.github.spotbugs.SpotBugsTask.createReports(SpotBugsTask.java:102)
at com.github.spotbugs.SpotBugsTask.<init>(SpotBugsTask.java:98)
at com.github.spotbugs.SpotBugsTask_Decorated.<init>(Unknown Source)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at org.gradle.internal.instantiation.generator.AsmBackedClassGenerator$InvokeConstructorStrategy.newInstance(AsmBackedClassGenerator.java:1969)
at org.gradle.internal.instantiation.generator.AbstractClassGenerator$GeneratedClassImpl$GeneratedConstructorImpl.newInstance(AbstractClassGenerator.java:468)
at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:64)
at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.newInstanceWithDisplayName(DependencyInjectingInstantiator.java:50)
at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:90)
... 190 more
my build.gradle
buildscript {
dependencies {
..
classpath 'gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.6.0'
..
}
}
apply plugin: 'com.github.spotbugs'
spotbugs {
toolVersion = "4.1.4"
}
tasks.withType(SpotBugsTask) {
xml.enabled = true
html.enabled = false
}
gradel.wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
gradle --version
------------------------------------------------------------
Gradle 6.7
------------------------------------------------------------
Build time: 2020-10-14 16:13:12 UTC
Revision: 312ba9e0f4f8a02d01854d1ed743b79ed996dfd3
Kotlin: 1.3.72
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM: 15.0.1 (Oracle Corporation 15.0.1+9)
OS: Mac OS X 10.15.7 x86_64
well, i think you should show your build.gradle, otherwise no one can help you.
my build.gradle:
plugins {
id "com.github.spotbugs" version "4.6.0"
}
// To generate an HTML report instead of XML
spotbugsMain {
reports {
xml.enabled = false
html.enabled = true
}
}
for:
------------------------------------------------------------
Gradle 6.6
------------------------------------------------------------
Build time: 2020-08-10 22:06:19 UTC
Revision: d119144684a0c301aea027b79857815659e431b9
Kotlin: 1.3.72
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM: 14.0.1 (Oracle Corporation 14.0.1+7)
OS: Mac OS X 10.15.7 x86_64
I'm using the Java-based Keycloak server and attempting to run the demo examples. I'm a bit of a Java hack, so please pardon my naiveté.
I'm getting the error shown below -- any help debugging and solving would be appreciated.
ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-7) Uncaught server error: java.lang.RuntimeException: org.eclipse.aether.collection.DependencyCollectionException: Failed to read artifact descriptor for org.keycloak:photoz-authz-policy:jar:3.4.3.Final
I had some trouble getting M2_HOME set so that keycloak could locate artifacts. I seem to be past that problem and now, but I'm not sure where to go with the above error. I've included some system info below. And if someone's really eager, the dockerfile is available.
I'm running v3.5.3 of maven:
$ mvn --version
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T19:49:05Z)
Maven home: /usr/local/apache-maven
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.9.60-linuxkit-aufs", arch: "amd64", family: "unix"
I ran mvn -U clean install in the project directory, and the artifacts appear to be built correctly:
[jboss#09fea4c663e0 ~]$ ll .m2/repository/org/keycloak/photoz-authz-policy/3.4.3.Final/
total 44
-rw-r--r-- 1 jboss jboss 5169 Mar 28 17:16 photoz-authz-policy-3.4.3.Final.jar
-rw-r--r-- 1 jboss jboss 32 Mar 28 17:16 photoz-authz-policy-3.4.3.Final.jar.md5
-rw-r--r-- 1 jboss jboss 40 Mar 28 17:16 photoz-authz-policy-3.4.3.Final.jar.sha1
-rw-r--r-- 1 jboss jboss 773 Jan 4 09:24 photoz-authz-policy-3.4.3.Final.pom
-rw-r--r-- 1 jboss jboss 32 Mar 28 17:16 photoz-authz-policy-3.4.3.Final.pom.md5
-rw-r--r-- 1 jboss jboss 40 Mar 28 17:16 photoz-authz-policy-3.4.3.Final.pom.sha1
-rw-r--r-- 1 jboss jboss 3859 Mar 28 17:16 photoz-authz-policy-3.4.3.Final-sources.jar
-rw-r--r-- 1 jboss jboss 32 Mar 28 17:16 photoz-authz-policy-3.4.3.Final-sources.jar.md5
-rw-r--r-- 1 jboss jboss 40 Mar 28 17:16 photoz-authz-policy-3.4.3.Final-sources.jar.sha1
-rw-r--r-- 1 jboss jboss 262 Mar 28 17:16 _remote.repositories
And finally, here's the metadata associated with the artifact:
[jboss#09fea4c663e0 ~]$ cat .m2/repository/org/keycloak/photoz-authz-policy/maven-metadata-local.xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>org.keycloak</groupId>
<artifactId>photoz-authz-policy</artifactId>
<versioning>
<release>3.4.3.Final</release>
<versions>
<version>3.4.3.Final</version>
</versions>
<lastUpdated>20180328171633</lastUpdated>
</versioning>
</metadata>
Any insight?
I was able to get the examples to run by copying the project files to the server and compiling on the server. That seems strange to me -- a fat WAR seems like it would make more sense. That is, I wouldn't expect to have to have supporting libraries compiled on a the server, but that strategy allowed me to move on. Here are the commands I ran on my wildfly server (Dockerfile commands):
# Build and install keycloak example libraries
WORKDIR /opt/jboss
USER jboss
COPY --chown=jboss:jboss _srv/keycloak-demo-3.4.3.Final ./_srv/keycloak-demo-3.4.3.Final
WORKDIR _srv/keycloak-demo-3.4.3.Final/examples
RUN mvn -U clean install
WORKDIR /opt/jboss
Creating a stand-alone client:
missing dependencies:
thufir#dur:~/NetBeansProjects/ejbClient$
thufir#dur:~/NetBeansProjects/ejbClient$ gradle runShadow
> Task :runShadow
Nov 06, 2017 11:16:38 AM net.bounceme.dur.ejb.client.App run
INFO: running..
Nov 06, 2017 11:16:38 AM net.bounceme.dur.ejb.client.App run
INFO: {org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, Context.SECURITY_PRINCIPAL=user1, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
Nov 06, 2017 11:16:38 AM net.bounceme.dur.ejb.client.App lookup
INFO: looking up jndi
Nov 06, 2017 11:16:38 AM net.bounceme.dur.ejb.client.App lookup
SEVERE: null
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.init(InitialContext.java:244)
at javax.naming.InitialContext.<init>(InitialContext.java:192)
at net.bounceme.dur.ejb.client.App.lookup(App.java:30)
at net.bounceme.dur.ejb.client.App.run(App.java:19)
at net.bounceme.dur.ejb.client.App.main(App.java:23)
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:672)
... 6 more
BUILD SUCCESSFUL in 1s
6 actionable tasks: 1 executed, 5 up-to-date
thufir#dur:~/NetBeansProjects/ejbClient$
adding erroneous (?) dependencies:
thufir#dur:~/NetBeansProjects/ejbClient$
thufir#dur:~/NetBeansProjects/ejbClient$ gradle clean build
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.glassfish.external:asm-all:3.3.
Searched in the following locations:
https://repo1.maven.org/maven2/org/glassfish/external/asm-all/3.3/asm-all-3.3.pom
https://repo1.maven.org/maven2/org/glassfish/external/asm-all/3.3/asm-all-3.3.jar
Required by:
project : > org.glassfish.main.appclient:gf-client:4.1 > org.glassfish.main.appclient:gf-client-module:4.1 > org.glassfish.main.ejb:ejb-full-container:4.1 > org.glassfish.main.ejb:ejb-container:4.1
project : > org.glassfish.main.appclient:gf-client:4.1 > org.glassfish.main.appclient:gf-client-module:4.1 > org.glassfish.main.deployment:dol:4.1 > org.glassfish.main.deployment:deployment-common:4.1
project : > org.glassfish.main.appclient:gf-client:4.1 > org.glassfish.main.appclient:gf-client-module:4.1 > org.glassfish.main.security:webservices.security:4.1 > org.glassfish.main.core:kernel:4.1 > org.glassfish.main.flashlight:flashlight-framework:4.1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
2 actionable tasks: 1 executed, 1 up-to-date
thufir#dur:~/NetBeansProjects/ejbClient$
the build.gradle file:
plugins {
id 'com.gradle.build-scan' version '1.8'
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '2.0.1'
}
buildScan {
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
licenseAgree = 'yes'
//publishAlways()
}
configurations {
provided
}
shadowJar {
baseName = 'ejbClient'
classifier = null
version = null
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'net.bounceme.dur.ejb.client.App'
repositories {
// jcenter()
mavenCentral()
}
configurations {
provided
}
dependencies {
provided 'javax:javaee-api:7.0'
compile group: 'org.glassfish', name: 'javax.json', version: '1.0.4'
// compile group: 'org.glassfish.main.appclient', name: 'gf-client', version: '4.1'
// compile group: 'org.glassfish.hk2.external', name: 'asm-all-repackaged', version: '2.1.88'
}
what are the dependencies to instantiate javax.name.Context objects? And, how are those depenendencies resolved in gradle?
Finally, trying to get javax.naming:
thufir#dur:~/NetBeansProjects/ejbClient$
thufir#dur:~/NetBeansProjects/ejbClient$ gradle clean runShadow
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.glassfish:javax.naming:1.0.4.
Searched in the following locations:
https://repo1.maven.org/maven2/org/glassfish/javax.naming/1.0.4/javax.naming-1.0.4.pom
https://repo1.maven.org/maven2/org/glassfish/javax.naming/1.0.4/javax.naming-1.0.4.jar
Required by:
project :
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
2 actionable tasks: 2 executed
thufir#dur:~/NetBeansProjects/ejbClient$
with gradle dependencies as:
dependencies {
provided 'javax:javaee-api:7.0'
compile group: 'org.glassfish', name: 'javax.naming', version: '1.0.4'
}
sorta kinda works:
thufir#dur:~$
thufir#dur:~$ appclient -client NetBeansProjects/ejbClient/build/libs/ejbClient.jar
Nov 06, 2017 12:10:08 PM net.bounceme.dur.ejb.client.App run
INFO: running..
Nov 06, 2017 12:10:08 PM net.bounceme.dur.ejb.client.App run
INFO: {java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
Nov 06, 2017 12:10:08 PM net.bounceme.dur.ejb.client.App lookup
INFO: looking up jndi
thufir#dur:~$
thufir#dur:~$ alias appclient
alias appclient='/home/thufir/GlassFish_Server/glassfish/bin/appclient '
thufir#dur:~$
meh.
I have an existing Spring app that I want to convert to a Spring Boot app. So I have added th Application.java file in my java source directory and execute my gradlwe script as usual. However, when I run the build command, a get an error saying 'unable to access jarfile' - although I specify the jarfile name in my build script and on my command line. Below is the build.gradle file and the output. What is wrong here?
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'spring-boot'
archivesBaseName = 'spring4'
version = '1'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web:1.3.3.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.3.3.RELEASE'
compile 'org.hibernate:hibernate-core:4.3.6.Final'
compile 'mysql:mysql-connector-java:5.1.31'
compile 'commons-dbcp:commons-dbcp:1.4'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat:1.3.3.RELEASE'
compile "ch.qos.logback:logback-classic:1.1.3"
compile "org.slf4j:log4j-over-slf4j:1.7.13"
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
testCompile("junit:junit")
}
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
configurations.all {
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j"
}
sourceSets {
main {
resources {
srcDirs "src/main/resources"
}
}
}
output:
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$ ./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:war
:bootRepackage
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 11.772 secs
Error: Unable to access jarfile build/libs/gs-spring-boot-0.1.0.jar
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$
check target directory:
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$ ll build/libs/
total 53697
drwxrwxrwx 1 vagrant vagrant 0 Sep 15 11:25 ./
drwxrwxrwx 1 vagrant vagrant 4096 Sep 13 09:54 ../
-rwxrwxrwx 1 vagrant vagrant 30698749 Sep 15 11:25 spring4-1.war*
-rwxrwxrwx 1 vagrant vagrant 24281990 Sep 15 11:24 spring4-1.war.original*
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$
I'm using Lombok in a pure-java module inside an Android Studio project. This is the build.gradle for the module:
apply plugin: 'java'
apply plugin: 'war'
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
providedCompile "org.projectlombok:lombok:1.12.6"
testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:1.7.0'
compile 'com.google.code.gson:gson:2.7'
}
However when I build my android module the resulting APK has these method counts from lombok, when it should have none.
lombok: 4099
bytecode: 85
core: 308
debug: 18
handlers: 8
runtimeDependencies: 15
delombok: 253
ant: 22
eclipse: 820
agent: 223
handlers: 387
experimental: 16
extern: 6
apachecommons: 1
java: 1
log4j: 2
slf4j: 2
installer: 286
eclipse: 109
javac: 970
apt: 132
handlers: 317
java6: 24
java7: 24
java8: 26
libs: 996
com: 61
zwitserloot: 61
cmdreader: 61
org: 935
objectweb: 935
asm: 935
commons: 405
signature: 41
tree: 199
patcher: 316
equinox: 18
inject: 7
scripts: 150
Is this something wrong w/ lombok, how I'm using providedCompile or something with the Android/Gradle build system?
You should use compileOnly instead.
Disclosure: I am a lombok developer and not a gradle expert.