This question already has answers here:
How to add a Maven project as a Gradle dependency?

(2个答案)


3个月前关闭。




我已经使用Maven项目创建了依赖 jar ,但是现在我必须将此Maven依赖添加到我的gradle项目中。
依赖关系在我的.m2目录中可用
正在从intellij获取以下错误。
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Cannot convert URL 'com.example.auth.security:common:0.0.1-SNAPSHOT.jar' to a file.


请找到我的build.gradle文件
plugins {
    id 'org.springframework.boot' version '2.1.16.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
    id 'war'
}

group = 'com.example.auth'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation files('com.example.auth.security:common:0.0.1-SNAPSHOT.jar')  --> getting error on this line.
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
    compileOnly 'org.projectlombok:lombok'
    implementation('io.jsonwebtoken:jjwt:0.9.1')

}
更新1
A problem occurred evaluating root project 'auth-center'.
> Supplied String module notation '0.0.1-SNAPSHOT' is invalid. Example notations: 'org.gradle:gradle-core:2.2', 'org.mockito:mockito-core:1.9.5:javadoc'.

最佳答案

您将需要添加一个本地Maven存储库,如下所示

repositories {
  maven { url new File(pathToYourM2Directory).toURI().toURL() }
}
此外,依赖项的声明不正确。它应该是
dependencies {
  implementation group: 'com.example.auth.security', name: 'common', version '0.0.1-SNAPSHOT'
}
您也可以修复files依赖性。但是,使用本地Maven回购协议(protocol)更具可持续性,因为通过这种方式解决 Artifact 可以在本地或远程解决 Artifact 的情况下对构建过程透明。

10-06 08:44
查看更多