Java 向gradle项目添加自定义maven依赖项

Java 向gradle项目添加自定义maven依赖项,java,maven,gradle,Java,Maven,Gradle,我已经使用maven项目创建了依赖项jar,但是现在我必须将这个maven依赖项添加到我的gradle项目中 依赖关系可在my.m2目录中找到 我从intellij收到以下错误 Execution failed for task ':compileJava'. > Could not resolve all files for configuration ':compileClasspath'. > Cannot convert URL 'com.example.auth.se

我已经使用maven项目创建了依赖项jar,但是现在我必须将这个maven依赖项添加到我的gradle项目中

依赖关系可在my
.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'
}

您还可以修复
文件
依赖关系。但是,使用本地maven repo更具可持续性,因为通过这种方式解决工件,如果工件在本地或远程解决,则构建过程是透明的。

由于我没有足够的声誉,因此无法发表评论。我认为您不应该试图将maven依赖项添加到gradle项目中。相反,将maven依赖项托管在别处,并配置gradle以从那里提取依赖项。作为参考,你可以看看这个答案


这是导入自定义java库(.jar)的另一种方法

您需要做的是,首先,在项目下的任何地方创建一个文件夹,在我的例子中是
/src/lib
,并将JAR文件放入该文件夹中。然后,把下面的代码写进你的Gradle文件

dependencies {
    //Library Auto Implement
    //Replace with your folder URI
    implementation(fileTree("./src/lib"))
}

然后Gradle将从该文件夹实现您的JAR文件,您就可以开始了。

这是因为
文件的参数。您应该传入jar文件的确切路径,而不是包名。这是否回答了您的问题?仅供参考,我正在使用Kotlin DSL。这仍然是error@Karthikeyan请将问题更新为新问题error@Karthikeyan请提供您的确切依赖声明