I am a new to Java, Gradle and Spring.
I setup a new project with the following gradle script:
buildscript {
repositories {
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT")
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
repositories {
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
When trying to build with the above script, I get the following errors:
E:\Projects\SpringAppTutorial>gradlew
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'SpringAppTutorial'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT.
Required by:
:SpringAppTutorial:unspecified
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT.
> Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-gradle-plugin/1.3.0.BUILD-SNAPSHOT/spring-boot-gradle-plugin-1.3.0.BUILD-20150531.081700-179.pom
> Could not resolve org.springframework.boot:spring-boot-tools:1.3.0.BUILD-SNAPSHOT.
> Could not resolve org.springframework.boot:spring-boot-tools:1.3.0.BUILD-SNAPSHOT.
> Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-tools/1.3.0.BUILD-SNAPSHOT/spring-boot-tools-1.3.0.BUILD-20150531.081700-180.pom
> Could not resolve org.springframework.boot:spring-boot-parent:1.3.0.BUILD-SNAPSHOT.
> Could not resolve org.springframework.boot:spring-boot-parent:1.3.0.BUILD-SNAPSHOT.
> Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-parent/1.3.0.BUILD-SNAPSHOT/spring-boot-parent-1.3.0.BUILD-20150531.081700-180.pom
> Could not resolve org.springframework.boot:spring-boot-dependencies:1.3.0.BUILD-SNAPSHOT.
> Could not resolve org.springframework.boot:spring-boot-dependencies:1.3.0.BUILD-SNAPSHOT.
> Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-dependencies/1.3.0.BUILD-SNAPSHOT/spring-boot-dependencies-1.3.0.BUILD-20150531.081700-181.pom
> Could not find org.springframework.data:spring-data-releasetrain:Fowler-RELEASE.
Searched in the following locations:
http://repo.spring.io/snapshot/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.pom
http://repo.spring.io/snapshot/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.jar
http://repo.spring.io/milestone/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.pom
http://repo.spring.io/milestone/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.jar
* 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: 15.726 secs
E:\Projects\SpringAppTutorial>
What am I doing wrong here?
You should be using a release version of the spring-boot gradle plugin - your script is using a development snapshot version string of some kind.
i.e. try
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}
(from http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html)
Assuming that works, you should be able to get rid of this section also:
repositories {
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
I have faced the same problem and as #skaffman suggests, I added version to my dependencies, it resolved.
implementation('org.springframework.session:spring-session:1.3.4.RELEASE')
runtimeOnly('com.okta.spring:okta-spring-boot-starter:0.6.1')
runtimeOnly('org.springframework.security.oauth:spring-security-oauth2:2.3.4.RELEASE')
Related
I am trying to run simply the Gluon single scene example. Here is my gradle output:
Configuration on demand is an incubating feature.
> Configure project :GluonApplicationApp
Project :GluonApplicationApp => no module-info.java found
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':GluonApplicationApp'.
> Could not create task ':GluonApplicationApp:debug'.
> Unnecessarily replacing a task that does not exist is not supported. Use create() or register() directly instead. You attempted to replace a task named 'debug', but there is no existing task with that name.
* 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.
* Get more help at https://help.gradle.org
My build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.17'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluonapplication.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:5.0.2'
}
jfxmobile {
downConfig {
version = '3.8.6'
// Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
}
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'org.openjfx:javafx-plugin:0.0.9'
}
}
apply plugin: 'org.openjfx.javafxplugin'
The JDK version i'm using is JDK 11, and I have tried various gradle versions. For my IDE I use netbeans.
I have been trying to fix this all day. Please help
I was using the old Gluon IDE plugin
Gluon build 0.1.29-SNAPSHOT fixes the rest of the problems
More details on comments of the question!
I want to introduce com.alibaba:fastjson:1.2.58 in my plugin project, but when gradle resolve dependencies, the org.jetbrains.intellij plugin redirect the download request to https://cache-redirector.jetbrains.com/www.jetbrains.com/intellij-repository/releases/com/alibaba/fastjson/1.2.58/fastjson-1.2.58.pom, which is not exists.
How can I force gradle download this dependency from mavenCentral ?
Here is my build.gradle:
buildscript {
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
url 'https://dl.bintray.com/jetbrains/intellij-plugin-service'
}
}
}
plugins {
id "org.jetbrains.intellij" version "0.4.4"
}
dependencies {
implementation 'com.alibaba:fastjson:1.2.58'
}
apply plugin: 'idea'
apply plugin: 'org.jetbrains.intellij'
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
intellij {
version ideaVersion
updateSinceUntilBuild false
plugins = [
"com.jetbrains.php:${phpPluginVersion}",
"com.jetbrains.php.blade:${bladePluginVersion}",
'CSS',
'java-i18n',
'properties',
'git4idea'
]
pluginName 'tw tools'
}
patchPluginXml {
sinceBuild '173'
}
group 'com.baiguiren'
version '1.2'
wrapper {
gradleVersion '5.4.1'
}
Output of ./gradlew clean && ./gradlew build:
BUILD SUCCESSFUL in 0s
1 actionable task: 1 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':prepareSandbox'.
> Could not resolve all files for configuration ':runtimeClasspath'.
> Could not find com.alibaba:fastjson:1.2.58.
Searched in the following locations:
https://cache-redirector.jetbrains.com/www.jetbrains.com/intellij-repository/releases/com/alibaba/fastjson/1.2.58/fastjson-1.2.58.pom
https://cache-redirector.jetbrains.com/www.jetbrains.com/intellij-repository/releases/com/alibaba/fastjson/1.2.58/fastjson-1.2.58.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIU/2018.3.5/3abea719ce307bc4f573cba4e3d86f4e35cab07/ideaIU-2018.3.5/com.alibaba/fastjson/1.2.58/ivy-1.2.58.xml
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIU/2018.3.5/3abea719ce307bc4f573cba4e3d86f4e35cab07/ideaIU-2018.3.5/fastjson-1.2.58-withKotlin-withSources.xml
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIU/2018.3.5/3abea719ce307bc4f573cba4e3d86f4e35cab07/ideaIU-2018.3.5/com.alibaba/fastjson/1.2.58/fastjson-1.2.58.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIU/2018.3.5/3abea719ce307bc4f573cba4e3d86f4e35cab07/ideaIU-2018.3.5/fastjson.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2018.3.5/78cbcd517ec112fbb0c7b45b00b464c1aa6371f3/fastjson-1.2.58-[classifier].jar
https://cache-redirector.jetbrains.com/plugins.jetbrains.com/maven/com/alibaba/fastjson/1.2.58/fastjson-1.2.58.pom
https://cache-redirector.jetbrains.com/plugins.jetbrains.com/maven/com/alibaba/fastjson/1.2.58/fastjson-1.2.58.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/com.alibaba/fastjson-1.2.58.xml
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIU/2018.3.5/3abea719ce307bc4f573cba4e3d86f4e35cab07/ideaIU-2018.3.5/plugins/fastjson/fastjson.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/fastjson-1.2.58/fastjson.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2018.3.5/78cbcd517ec112fbb0c7b45b00b464c1aa6371f3/fastjson-2018.3.5.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
I have tried to Invalid caches and restart, but not work.
I even tried to remove org.jetbrains.intellij plugin, but it's required by the project.
There is nothing wrong with cache-redirector, it's just one of the repositories registered in the project, Gradle checks them all.
Try to add the mavenCentral repo to your build.gradle (at the moment it's defined for buildscript only):
repositories {
mavenCentral()
}
This is how i have added dependencies in my build.gradle
// Dependency Versioning
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Edgware.RELEASE'
mavenBom 'io.pivotal.spring.cloud:spring-cloud-services-dependencies:1.5.0.RELEASE'
mavenBom 'org.springframework.boot:spring-boot-dependencies:1.5.15.RELEASE'
}
dependencies {
dependency 'io.springfox:springfox-swagger2:2.8.0'
dependency 'io.springfox:springfox-swagger-ui:2.8.0'
dependency 'org.flywaydb:flyway-core:4.2.0'
dependency 'com.microsoft.sqlserver:mssql-jdbc:6.2.2.jre8'
}
}
I am looking to add a custom-number with each dependency. This number is our Approval number provided by our Architecture team for approval of using that dependency within our enterprise..
Say if my Architecture team has Approved to use io.springfox:springfox-swagger2:2.8.0 dependency and if the approval number is APPL-1054 then i have to add this number also as a metadata along within the dependency tag with which i will have a different gradle task to consume those numbers
something that looks like dependency 'io.springfox:springfox-swagger2:2.8.0' : APPL-1054
Please help with your ideas
You could set the approvals in a Map then use dependency resolution to validate the approvals. The map could come from some web source as long as you can get it to a map somehow. Here is a simple example
buildscript {
repositories {
jcenter()
}
dependencies {
gradleApi()
}
}
group 'com.stackoverflow'
version '1.0-SNAPSHOT'
repositories {
jcenter()
}
configurations {
audited.extendsFrom(compile)
}
Map<String, Object> approvedDeps = [
'junit:junit:4.12': 'APPROVAL-1234'
]
dependencies {
compile gradleApi()
audited 'junit:junit:4.12'
audited 'org.mockito:mockito-android:2.22.0'
}
dependencies {
components {
all { ComponentMetadataDetails details ->
String requestedArtifact = "${details.id.group}:${details.id.name}:${details.id.version}"
String approvalCode = approvedDeps[requestedArtifact]
if (approvalCode == null) {
throw new GradleException("Use of unapproved dependency (${requestedArtifact})")
}
logger.lifecycle("Requested dependency (${requestedArtifact}) is approved: ${approvalCode}")
return details
}
}
}
// lets fake some action that would trigger dependency resolution
configurations.eachWithIndex { Configuration entry, int index ->
if (entry.canBeResolved) {
entry.resolve()
print("Resolved index: ${index}")
}
}
Now if we run ./gradlew clean build we get an error as an unapproved dependency was added.
$ ./gradlew clean build
> Configure project :
Requested dependency (junit:junit:4.12) is approved: APPROVAL-1234
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/jonstanford/dev/stackoverflow/q52427676/build.gradle' line: 36
* What went wrong:
A problem occurred evaluating root project 'q52427676'.
> Could not resolve all dependencies for configuration ':audited'.
> There was an error while evaluating a component metadata rule for org.mockito:mockito-android:2.22.0.
> Use of unapproved dependency (org.mockito:mockito-android:2.22.0)
* 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.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
Of course you could move this functionality to a custom plugin or such but I think the base idea holds.
build.gradle (unnecessary parts were ommited):
apply plugin: 'java'
repositories {
mavenCentral()
maven {
credentials {
username "$mavenUser"
password "$mavenPassword"
}
url "http://localhost:8081/nexus/content/groups/public"
}
}
dependencies {
compile("com.example:some-lib:1.0.0-RELEASE")
}
Assume that the defined dependency is missing in configured Maven repository. When ./gradlew clean build tasks are executed the application is built successfully, although the required dependencies are missing.
Is there a way to configure Gradle to fail if there are unresolved dependencies?
Relates to:
How to make Gradle fail the build if a file dependency is not found? - Solution provided there is not applicable.
Consider this build.gradle (note: intentionally bogus jar specified in dependencies):
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile("junit:junit:4.12")
compile("junit:junitxyz:51.50")
}
task checkDependencies() {
doLast {
configurations.compile.each { file ->
println "TRACER checking: " + file.name
assert file.exists()
}
}
}
compileJava.dependsOn checkDependencies
example output:
$ gradle -q clean compileJava
FAILURE: Build failed with an exception.
[snip]
* What went wrong:
Execution failed for task ':checkDependencies'.
> Could not resolve all files for configuration ':compile'.
> Could not find junit:junitxyz:51.50.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/junit/junitxyz/51.50/junitxyz-51.50.pom
- https://repo.maven.apache.org/maven2/junit/junitxyz/51.50/junitxyz-51.50.jar
I have a custom gradle plugin in which custom task types and gradle configurations are added. When I apply this plugin before maven-publish it works perfectly fine. But when I add it after apply plugin: 'maven-publish', it fails with error message :
FAILURE: Build failed with an exception.
* Where:
Build file '/scratch/skgupta/git_storage/emdi/integtest/build.gradle' line: 38
* What went wrong:
A problem occurred evaluating root project 'integtest'.
> Cannot configure the 'publishing' extension after it has been accessed.
* 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: 7.6 secs
Here is the build.gradle file.
buildscript {
repositories {
maven {
url = "${artifactory_contextUrl}/repo"
}
}
dependencies {
classpath group: 'com.mycomp.proj', name: 'MyCustomPlugin', version: "${pluginVersion}", transitive: true
}
}
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'MyCustomPlugin' // WHen this line is moved above maven-publish, build works fine.
// add jar name and version
jar.archiveName='lrgemaas_small_deploy_3n.jar'
group = 'com.mycom.proj.test'
version = '1.0.3'
dependencies {
compile group: 'eaas.platform', name: 'registry-lookup-client', version: '0.1'
compile group: 'eaas.platform', name: 'registry-client', version: '0.1'
compile configurations.lrgConfig // This configuration is added by MyCustomPlugin
compile configurations.webdriver // This configuration is added by MyCustomPlugin
}
repositories {
maven {
url = "${artifactory_contextUrl}/repo"
}
}
publishing {
publications {
myPublicationName(MavenPublication) {
artifactId 'lrgemaas_small_deploy_3n'
artifact jar.archivePath
}
}
repositories {
maven {
url = "${artifactory_contextUrl}/${artifactory_repoName}"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
}
// workflow for build
defaultTasks 'clean','build','publish'
PS: I tried doing nothing in the custom plugin (i.e., simply return from apply method), but it still gives same error.
Simply replacing:
publishing {
publications {
...
}
}
with following:
publishing.publications {
...
}
worked for me!
Gradle is brittle regarding the order of the plugins. There is a discussion about this exact issue at
https://discuss.gradle.org/t/apply-maven-publish-plugin-from-init-script/2460
"Cool, so this is what happens.
DefaultPublishingExtension which is backing the 'publishing {}' block is a DeferredConfigurable. It's a mechanism that allows to register a configuration block to be executed when an extension is accessed. Unfortunately sometimes it causes unexpected behaviour if you access this kind of extension unawares. This is exactly the case when for example you try to get all the properties of a project (as the release plugin does here: https://github.com/townsfolk/gradle-release/blob/master/src/main/groovy/release/PluginHelper.groovy#L230"
FYI, I use a dynamic version and found that I had to define version prior to apply of my plugins. Probably because java or maven-publish sets the publication details upon application.
I upgraded gradle version from 2.1 to 2.12 and it solved this problem, fwiw.