I was trying to run a legacy project using spring version 3 with build.gradle:
...
plugins {
id 'java'
id 'maven-publish'
id 'war'
}
repositories {
mavenLocal()
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
}
ext {
org_springframework_version = '3.2.18.RELEASE'
}
dependencies {
...
implementation 'org.springframework.ldap:spring-ldap-core:2.4.1'
implementation "org.springframework:spring-web:${org_springframework_version}"
implementation "org.springframework:spring-webmvc:${org_springframework_version}"
implementation "org.springframework:spring:${org_springframework_version}"
...
}
...
but getting the following error when trying to build:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.springframework:spring:3.2.18.RELEASE.
Searched in the following locations:
- file:/C:/Users/.../.m2/repository/org/springframework/spring/3.2.18.RELEASE/spring-3.2.18.RELEASE.pom
- https://repo.maven.apache.org/maven2/org/springframework/spring/3.2.18.RELEASE/spring-3.2.18.RELEASE.pom
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
I checked https://repo.maven.apache.org/maven2/org/springframework/spring/ and it looks like there is no spring 3 or 4 in the repo.
I cannot use any newer spring version as there are tons of other dependencies and legacy code in the project that should be kept as is.
I am confused as to why is this the case or how to build my project now.
Any help is appreciated.
PS. A little background: I have a legacy project that relies on really old tech (Stripes framework) which is straight up refusing to work with spring 5+. It is running on Java 6 now. I want to upgrade it to java 8. But spring 2.x dependency is not letting me to.
The fullblown spring.jar hasn't been available since Spring Framework 3.0.0. Spring 2.5.6 is the last one that has the full Spring jar. Since then only the smaller modules have been available.
The versions for 5.x you see are only some top level pom.xml files which, I assume, have been published accidentally (as for 6.x they aren't there anymore).
In short remove the following line from your dependencies
implementation "org.springframework:spring:${org_springframework_version}"
So it doesn't try to resolve something that hasn't been available since Spring 2.5.6 anymore. What you should include are the dependencies for the modules you need (something like the below dependencies).
implementation "org.springframework:spring-web:${org_springframework_version}"
implementation "org.springframework:spring-webmvc:${org_springframework_version}"
implementation "org.springframework:spring-jdbc:${org_springframework_version}"
implementation "org.springframework:spring-orm:${org_springframework_version}"
implementation "org.springframework:spring-oxm:${org_springframework_version}"
As an additional note replace
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
with
mavenCentral()
This will allow Gradle to pick a better suited mirror of Maven for your environment.
Related
Im have my library, for help me with spring stuff, build.gradle looks like
plugins {
id 'java-library'
id 'maven-publish'
id "io.spring.dependency-management" version "1.0.11.RELEASE"
}
dependencyManagement {
imports {
mavenBom 'org.springframework.boot:spring-boot-dependencies:2.7.0'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
}
publishing {
// Default maven publish settings
}
When publishing, Gradle generates .module files, and then if the library is used by gradle, it prioritizes .module files over .pom files
The problem is that no dependencyManagement information is written to the .module file, and so when I try to use the library in another project, I get
Could not determine the dependencies of task ':shadowJar'.
> Could not resolve all dependencies for configuration ':runtimeClasspath'.
> Could not find org.springframework.boot:spring-boot-starter-data-mongodb:.
Required by:
project : > project :database > ru.spliterash:spcore-spring-database-mongo:1.0.0-SNAPSHOT:20220714.235637-1
I can solve this problem by disabling the generation of .module files, and gradle will have to use a pom file in which the version is written, but maybe if there is some more correct solution, because it seems to me that this is not entirely correct
I have found a solution to the problem.
In new versions of gradle, this appeared as a built-in solution, and now spring dependency management plugin is not needed. In order to add a maven bom, it is enough just to write, and it will be correctly entered into the module file
dependencies {
implementation(platform('org.springframework.boot:spring-boot-dependencies:2.7.0'))
implementation(platform('org.springframework.cloud:spring-cloud-dependencies:2021.0.2'))
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
}
I'm new to Gradle so I have awfully big problems and one of them is about the Oracle JDBC driver. I just want to get connection to DB and I already used a JDBC driver in my previous project, but that did not use Gradle. Now, I see that I have to show dependency on driver, but this just didn't work. I already used all of the advice I found:
I tried to add connector.jar to VM options,
to create dependency with implementation("com.oracle.database.jdbc:ojdbc8:21.1.0.0"), but it simply doesn't work.
After I use compile 'com.oracle:ojdbc8:21.1.0.0', I got Could not find method compile() for arguments [com.oracle:ojdbc8:21.1.0.0] and that's just killing me.
I also tried to use local Maven repository and I have downloaded .jar, but it doesn't work either.
I also just tried to add this lib dependency in IntelliJ, using File->Project Structure->+ and creating ojdbc8 class with path to this file directly.
Full version of my build.gradle file:
plugins {
// Apply the application plugin to add support for building a CLI application in
Java.id 'application'
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
mavenLocal()
}
dependencies {
implementation("com.oracle.database.jdbc:ojdbc8:21.1.0.0")
compile 'com.oracle:ojdbc8:21.1.0.0'
// Use JUnit test framework.
testImplementation 'junit:junit:4.13.2'
implementation 'com.h2database:h2:1.4.199'
implementation 'org.hibernate:hibernate-core:5.4.2.Final'
// This dependency is used by the application.
implementation 'com.google.guava:guava:30.1.1-jre'
}
application {
mainClass = 'model.App'
}
I'd like to use this JDBC driver in one class, but I just can't. Can you help me, please?
I'm trying to generate signed apk and I keep getting this error. I searched on Google for the error but haven't come up with anything solid. Any help would be great. Thank you.
Task :app:processReleaseManifest FAILED [com.facebook.android:audience-network-sdk:6.4.0] /Users/xxxx/.gradle/caches/transforms-2/files-2.1/1208b0b00589b6f8b9220695fa10ec7b/audience-network-sdk-6.4.0/AndroidManifest.xml:12:9-55 Error: Missing 'package' key attribute on element package at [com.facebook.android:audience-network-sdk:6.4.0] AndroidManifest.xml:12:9-55 [com.facebook.android:audience-network-sdk:6.4.0] /Users/xxxx/.gradle/caches/transforms-2/files-2.1/1208b0b00589b6f8b9220695fa10ec7b/audience-network-sdk-6.4.0/AndroidManifest.xml Error: Validation failed, exiting
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
Execution failed for task ':app:processReleaseManifest'.
> Manifest merger failed with multiple errors, see logs
It's probably because some changes the Android team has made on Gradle. Right now, if your Gradle version is lower than 4.1, you'll probably see one or a combination of these errors:
Android resource linking failed /Users/sample/AndroidStudioProjects/MyApp/app/build/intermediates/merged_manifests/debug/AndroidManifest.xml:18: error: unexpected element <queries> found in <manifest>
Manifest merger failed with multiple errors, see logs
Error: Missing 'package' key attribute on element package
To solve them, they suggest doing one of two things:
1. Upgrade your Gradle to 4.1 version or higher
Just update your build.gradle file by changing the version in the classpath.
buildscript {
repositories {
// Gradle 4.1 and higher include support for Google's Maven repo using
// the google() method. And you need to include this repo to download
// Android Gradle plugin 3.0.0 or higher.
google()
...
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0' //change it here
}
}
2. Update your Gradle to a version compatible with your current version
If you don't want to update your Gradle to the latest version, you can stick with your current by changing it to a dot release equivalent to the version you are using without having to worry with compatibility issues.
Your current version
Dot release equivalent
4.1.*
No upgraded needed
4.0.*
4.0.1
3.6.*
3.6.4
3.5.*
3.5.4
3.4.*
3.4.3
3.3.*
3.3.3
So for instance, if you're running your app at 4.0.0 you just change it to 4.0.1 also in the build.gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
// classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:4.0.1'
}
}
Google suggests using the second option if your app is depending on third party APIs or old Gradle versions.
We know that not everyone is ready to upgrade to the latest version, though, and you may be relying on old versions of Gradle or libraries that aren’t compatible with 4.1.
You can learn more about what's changed in their official post here.
Having a gradle project.
When i'm trying to build project.
buildscript {
ext {
springBootVersion = '2.2.4.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "gradle.plugin.org.hidetake:gradle-swagger-generator-plugin:2.9.0"
classpath "net.ltgt.gradle:gradle-apt-plugin:0.21"
}
}
plugins {
id "net.ltgt.apt-eclipse" version "0.21"
id "net.ltgt.apt-idea" version "0.15"
id "net.ltgt.apt" version "0.15"
}
I have error which is connected with plugins
Plugin [id: 'net.ltgt.apt-eclipse', version: '0.15'] was not found in any of the following sources:
How to fix it?
I was facing the same issue. In build.gradle, the paths provided for the dependencies weren't matching the folders specified. Placing the folders in the mentioned path shown in the build.gradle solved it. After that I was able to build the project without errors.
TL;DR: If you are using a current gradle version, it's fine to just drop all of the net.ltgt.apt dependencies. You will not need it anymore because, it's features are now available natively in Gradle.
More details:
From the plugin README.md (https://github.com/tbroyer/gradle-apt-plugin#readme)
The goal of this plugin was to eventually no longer be needed, being superseded by built-in features. This has become a reality with Gradle 5.2 and IntelliJ IDEA 2019.1. tl;dr: this plugin is obsolete, don't use it. If you're using Eclipse though, continue reading.
It originally did a few things to make it easier/safer to use Java annotation processors in a Gradle build. Those things are now available natively in Gradle, so what's this plugin about?
If you use older versions of Gradle (pre-4.6), you can still benefit from those features:
it ensures the presence of configurations for your compile-time only dependencies (annotations, generally) and annotation processors, consistently across all supported Gradle versions;
automatically configures the corresponding JavaCompile and GroovyCompile tasks to make use of these configurations, when the java or groovy plugin is applied.
With recent versions of Gradle (between 4.6 and 5.1), this plugin will actually only:
add some DSL to configure annotation processors; it is however recommended to directly configure the tasks' options.compilerArgs;
backport the sourceSet.output.generatedSourcesDirs Gradle 5.2 API;
configure JavaCompile and GroovyCompile tasks' options.annotationProcessorGeneratedSourcesDirectory with a sane default value so you can see the generated sources in your IDE and for debugging, and avoid shipping them in your JARs.
TL;DR Two gradle plugins use different versions of the same dependency, resulting in compile errors when one of the plugins is invoked.
The Situation
I have a Java project compiled using Gradle 4.x.
The project relies on two plugins: gradle-jaxb-plugin and serenity-gradle-plugin.
Both plugins share a dependency, guice.
The Problem
I need to upgrade one of the plugins (serenety). The upgrade results in a conflict at the point in which the jaxb plugin is invoked.
...
Caused by: java.lang.NoClassDefFoundError: com/google/inject/internal/util/$Maps
at com.google.inject.assistedinject.BindingCollector.<init>(BindingCollector.java:34)
at com.google.inject.assistedinject.FactoryModuleBuilder.<init>(FactoryModuleBuilder.java:206)
at org.openrepose.gradle.plugins.jaxb.schema.guice.DocSlurperModule.configure(DocSlurperModule.groovy:43)
...
I did some sleuthing and googling, and am fairly sure that the issue is rooted in the fact that the version of the serenity plugin uses guice 4.x when it used to use guice 3.x. The jaxb plugin uses guice 3.x.
The Question
How do I separate the plugin dependencies from one another? I would like to include both plugins, but it appears that gradle will take the highest dependency set and use that everywhere.
The Code
Here are the relevant portions of my build.gradle
buildscript {
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'gradle.plugin.org.openrepose:gradle-jaxb-plugin:2.4.1'
classpath 'net.serenity-bdd:serenity-gradle-plugin:1.5.1'
}
}
...
project(':integration-tests') {
apply plugin: 'java'
apply plugin: 'net.serenity-bdd.aggregator'
...
}
...
project(':cms-business-model') {
apply plugin: 'org.openrepose.gradle.plugins.jaxb'
apply plugin: 'java'
...
}
Note: You can replicate the issue by adding the serenity 1.5.1 plugin to the classpath dependencies block of the jaxb plugin examples
TL;DR: When Gradle plugins share a dependency but use different versions of that dependency only the highest version is actually used. You have to explicitly exclude the higher-dependency version.
The conflict here came because the jaxb plugin depends on guice:3.0 AND guice-assistedinject:3.0.
When serenity uses guice:4.0 there was a version mismatch between guice:4.0 and guice-assistedinject:3.0
The solution is to exclude the guice dependency from serenity, therefore falling back on guice:3.0
Updated Code
buildscript {
repositories {
mavenCentral()
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'gradle.plugin.org.openrepose:gradle-jaxb-plugin:2.4.1'
classpath ('net.serenity-bdd:serenity-gradle-plugin:1.5.1') {
exclude group: 'com.google.inject', module:'guice'
}
}
}
...
Alternative Solution
Another possibility may have been to require guice-assistedinject:4.0, but the above worked so I didn't continue to explore.