java - 将自定义 Maven 依赖项添加到 gradle 项目

标签 java maven gradle

<分区>

我已经使用 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 存储库更可持续,因为通过这种方式解析 Artifact ,无论 Artifact 是在本地还是远程解析,它对于构建过程都是透明的。

关于java - 将自定义 Maven 依赖项添加到 gradle 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63252543/

相关文章:

java - Java平台库支持https吗

java - Android 版本冲突gradle

gradle - 构建时如何确保在编译之前生成代码?

java - 如何运行Maven编译的程序?

mysql - Spring Boot Maven和MySQL错误处理

java - CheckStyle SuppressionFilter 模块文件路径以实现 Eclipse 和 Maven 兼容性

android - 根据buildType更改android项目中的.properties文件和settings.gradle文件

java - Jackson/Gson 能给我所有已知的可反序列化字段名称吗?

Java - EC2 实例的 HTTPS GET 调用因握手失败而失败,在本地工作

java - OrientDB连接池