I am trying to build simple hello world spring-boot project with gradle and groovy.
When I run 'gradle clean build', I am getting below error.
So far I tried,
Even though it is a gradle project, I updated the maven version to latest(3.6.3). Just to be a safer side.
I re-installed my intelliJ IDE
I added maven url as "https:" in build.gradle
After above steps, still I am getting below error. I am not sure what else I am missing.
Though I have given 'https:' url in gradle build file, I am not sure from where it is taking the non-secure url(http).
Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all dependencies for configuration ':detachedConfiguration1'.
> Could not resolve org.springframework.boot:spring-boot-dependencies:2.1.1.RELEASE.
Required by:
project :
> Could not resolve org.springframework.boot:spring-boot-dependencies:2.1.1.RELEASE.
> Could not get resource 'http://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.1.1.RELEASE/spring-boot-dependencies-2.1.1.RELEASE.pom'.
> Could not HEAD 'http://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.1.1.RELEASE/spring-boot-dependencies-2.1.1.RELEASE.pom'. Received status code 501 from server: HTTPS Required
And my gradle build file looks:
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'war'
}
group = 'com.own.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenLocal()
maven {
url = 'https://repo.maven.apache.org/maven2'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
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()
}
Finally, I figured out where to update the maven url to "https://*" for gradle projects.
$ vi ~/.gradle/init.gradle
then I updated the maven url to secure protocol ("https://...")
allprojects {
repositories {
mavenLocal()
// Any Organization/Company specific repo url goes here
maven {
url "https://repo1.maven.org/maven2"
}
}
}
After above steps, it worked for me and able to build the spring-boot application successfully.
Using start.spring.io, this is the content of the build.gradle generated there:
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'groovy'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.codehaus.groovy:groovy'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
Note the major differences:
groovy is actually there as plugin and as dependency
the maven repo is secure. As the error message states, you have use
the https endpoint here
Related
I'm following a tutorial on publishing artifacts to Nexus and a simple Java app is used as an example. A Gradle file is provided and meant to be changed. In the end, it looks like this:
plugins {
id 'java'
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
}
group 'com.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
artifacts("build/libs/my-app-$version"+".jar") {
extension = 'jar'
}
}
}
repositories {
maven {
name'nexus'
url "http://someip:someport/repository/maven-snapshots/"
credentials {
username project.repoUser
password project.repoPassword
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '5.2'
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
I when I use the command ./gradle build I get the following error:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/matteo/Desktop/devops_bootcamp/java-app/build.gradle' line: 14
* What went wrong:
A problem occurred evaluating root project 'my-app'.
> No signature of method: build_49q3y83g7hdxe5s51k5187z33.publishing() is applicable for argument types: (build_49q3y83g7hdxe5s51k5187z33$_run_closure1) values: [build_49q3y83g7hdxe5s51k5187z33$_run_closure1#79692f52]
Gradle version: Gradle 7.4.2
What am I doing wrong?
The "no signature of method" problem is a bug that happens when a closure can't compile. It should be fixed in the upcoming Gradle version 7.5.
The reason that it can't compile is because artifacts is a property and extension is a method (you have them both the other way around). There is also a method called artifact (in singular) that you probably want to use.
It is difficult to just guess what syntax to use, so check the documentation on it here.
There are various ways you can express this publication, but one is like the snippet below.
publications {
maven(MavenPublication) {
artifact("build/libs/my-app-$version"+".jar") {
extension('jar')
}
}
}
I created a new Gradle project today in IntelliJ and couldn't build it, every time it failed with this error:
> Could not resolve org.springframework:spring-core:5.3.17.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:2.6.5 > org.springframework.boot:spring-boot-gradle-plugin:2.6.5
> Could not resolve org.springframework:spring-core:5.3.17.
> Could not get resource 'https://plugins.gradle.org/m2/org/springframework/spring-core/5.3.17/spring-core-5.3.17.pom'.
> Could not GET 'https://repo.gradle.org/artifactory/jcenter/org/springframework/spring-core/5.3.17/spring-core-5.3.17.pom'.
> Read timed out
Since the reported URL contains 'jcenter' in it, I'm wondering if the failure it related to JCenter shutdown. I couldn't explain how it happened since I use mavenCentral repository.
This is my very simple build.gradle file:
plugins {
id 'org.springframework.boot' version '2.6.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'org.sample'
version = '1.0.0'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
When I tried to open https://plugins.gradle.org/m2/org/springframework/spring-core/5.3.17/spring-core-5.3.17.pom in browser, HTTP 303 was returned + location = https://repo.gradle.org/artifactory/jcenter/org/springframework/spring-core/5.3.17/spring-core-5.3.17.pom .
Does anyone face the same issue?
I am trying to test setting up a minimal project, building and exporting it as a jar, and using that project as a dependency in another. I am using Spring for this. I have two projects, makeajar and useajar. In makeajar, I set up a simple project with a Java class called Dinner. I want to import the jar for this project as part of the library in useajar, and from useajar instantiate a Dinner object.
However, the issue I'm getting is that I can't import the Dinner class. When I do, the import shows red:
Is there something I'm doing wrong in this process?
Things I've already tried:
Invalidating caches and restarting
Creating a fresh project
Adding makeajar as a module dependency (note: This was already there, and also appeared in the Project Structure -> Libraries)
How I produce the jar file from makeajar:
Go to project root directory and run ./gradlew build
Things I'm noticing:
Although makeajar appears in my module dependencies and libraries, it does not appear in the "External Libraries" folder in the useajar project.
I can gradle refresh fine, and if I comment out the attempts to import the Dinner object, I build.
I can easily get various popular dependencies (i.e. Jackson, guava) from MavenCentral and use these right out of the box. The issue is only occurring with my makeajar dependency.
makeajar build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.12.BUILD-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.makingajar'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
useajar build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.12.BUILD-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'idea'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
apply plugin: 'idea'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
mavenLocal {
flatDir {
dirs projectDir.toString() + '/libs'
}
}
}
allprojects {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation 'com.makingajar:makeajar2:0.0.1-SNAPSHOT'
implementation 'com.fasterxml.jackson.core:jackson-core:2.11.3'
}
}
test {
useJUnitPlatform()
}
IntelliJ version 2020.1.4
Gradle version 6.6.1
I was trying to make a jar with dependencies because I was getting a NoClassDefFoundError when starting the jar with java -Dspring.config.location=myProperties -jar myJar, after a lot of searching I found that I can achieve this using the following solution in the jar block:
from{
configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it)}
}
And all good with this except for the amount of time when building the jar (1 minute aprox), and according with this answer: Gradle: Build 'fat jar' with Spring Boot Dependencies I don't need to create an additional task, is enough with the bootRepackage but I'm getting the error that I mentioned above with bootRepackage and I don't understand why.
This is the content of my build.gradle and I'm using spring boot 1.5.15:
/*
* This file was generated by the Gradle 'init' task.
*/
buildscript {
ext.springBootVersion = '1.5.15.RELEASE'
ext.managementVersion = '1.0.6.RELEASE'
ext.axis2Version = '1.7.9'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
//classpath "io.spring.gradle:dependency-management-plugin:${managementVersion}"
//classpath "com.intershop.gradle.wsdl:wsdl-gradle-plugin:2.0.1"
}
}
plugins {
id 'java'
id 'maven'
id 'org.springframework.boot' version '1.5.15.RELEASE'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
}
configurations{
implementation{
exclude group: 'javax.servlet', module: 'servlet-api'
}
}
dependencies {
implementation "org.springframework.boot:spring-boot-starter:${springBootVersion}"
implementation 'org.springframework.integration:spring-integration-mongodb'
implementation 'org.springframework.integration:spring-integration-amqp'
testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
testImplementation 'org.mockito:mockito-core:2.6.1'
implementation 'org.apache.ws.commons.axiom:axiom-jaxb:1.2.20'
implementation('org.apache.axis2:axis2-kernel:1.7.9'){
exclude group: 'javax.servlet', module: 'servlet-api'
//The exclude above don't work
}
implementation "org.apache.axis2:axis2-kernel:${axis2Version}"
implementation "org.apache.axis2:axis2-wsdl2code-maven-plugin:${axis2Version}"
implementation "org.apache.axis2:axis2-transport-http:${axis2Version}"
}
wsdl {
axis2 {
genNameAxis2 {
//someAxis2Tasks
}
}
}
wsdl2java {
//someWsdlTasks
}
wsdl2javaExt {
cxfVersion = "3.2.1"
}
jar {
manifest{
attributes ('Main-Class': 'dummy.Application')
}
from{
configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it)}
}
archiveBaseName = 'projectName'
archiveVersion = '1.0.0'
}
bootRepackage{
mainClass = 'dummy.Application'
//classifier = 'boot' I'm getting an error with this argument
}
repositories {
mavenLocal()
}
group = 'dummy.group'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
Thank you in advance.
I have this same problem after upgrading to Gradle 5 and using 'implementation' instead of 'compile' for my dependencies.
Gradle built a main jar with no sub-project jars or dependencies (no BOOT-INF/lib directory at all). Changing 'implementation' back to 'compile' in the parent project only fixed the problem (with no other changes).
So, apparently, the Spring Boot 1.5.9 Gradle plugin does not work with the new implementation configuration. Note that Spring Boot 2 and the new bootJar task work fine, this issue is only with the old bootRepackage and the new implementation configuration.
This is my build.gradle file
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'yBayApplication'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
springBoot {
mainClass = "com.ybayApplication.customerAccount.CustomerServiceApplication"
}
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-eureka-server:1.2.3.RELEASE')
compile('org.springframework.cloud:spring-cloud-starter-zuul')
compile group: 'com.netflix.zuul', name: 'zuul-core', version: '2.0.0-rc.1'
compile group: 'com.netflix.governator', name: 'governator-archaius', version: '1.6.0'
compile group: 'io.reactivex', name: 'rxjava-string', version: '0.22.0'
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.h2database:h2")
testCompile("junit:junit")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.BUILD-SNAPSHOT"
}
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
And this is the error message, I am receiving while building the gradle.
Gradle Distribution: Local installation at C:\gradle\gradle-3.4.1
Gradle Version: 3.4.1
Java Home: C:\Program Files (x86)\Java\jdk1.8.0_121
JVM Arguments: None
Program Arguments: None
Gradle Tasks: clean build
:clean UP-TO-DATE
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':detachedConfiguration5'.
> Could not find com.netflix.governator:governator-archaius:1.6.0.
Searched in the following locations:
https://repo1.maven.org/maven2/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.pom
https://repo1.maven.org/maven2/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.jar
https://repo.spring.io/snapshot/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.pom
https://repo.spring.io/snapshot/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.jar
https://repo.spring.io/milestone/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.pom
https://repo.spring.io/milestone/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.jar
Required by:
project :
project : > com.netflix.zuul:zuul-core:2.0.0-rc.1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.77 secs
As you can see in the build.gradle file, I have added the missing dependency as well. I am tying to implement a Zuul filter based on this example in gradle https://spring.io/guides/gs/routing-and-filtering/.
On the first look, it looks like you need to remove the
compile group: 'com.netflix.zuul', name: 'zuul-core', version: '2.0.0-rc.1'
The compile('org.springframework.cloud:spring-cloud-starter-zuul') is dependent on zuul core so it will download it.
Additionally, for the governator-archaius I don't see the version 1.6.0.
I think you meant 1.16.0. Look at the link here to grab the accurate version https://mvnrepository.com/artifact/com.netflix.governator/governator-archaius
Let me know if this solves your problem.