有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用SBT将工件发布到本地maven repo,并在Gradle项目中使用它

以下是我想做的:

  • 在Scala sbt项目中,我想将一个工件发布到我的本地maven存储库中
  • 之后,我想在一个基于Gradle的Java项目中使用这个工件

这就是我挣扎的地方:

  • 我已经使用sbt publishM2成功地发布了这个工件。以下是我的build.sbt
organization := "com.example"
name := "my.messaging"
version := "0.1"
scalaVersion := "2.12.8"
publishMavenStyle := true

这将在此处生成工件:

C:\Users\BAIERLF\.m2\repository\com\example\my-messaging_2.12\0.1

POM文件如下所示:

<?xml version='1.0' encoding='UTF-8'?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>my-messaging_2.12</artifactId>
    <packaging>jar</packaging>
    <description>my.messaging</description>
    <version>0.1</version>
    <name>my.messaging</name>
    <organization>
        <name>com.example</name>
    </organization>
    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.12.8</version>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>ArtimaMavenRepository</id>
            <name>Artima Maven Repository</name>
            <url>http://repo.artima.com/releases/</url>
            <layout>default</layout>
        </repository>
    </repositories>
</project>

我发现自己无法在Gradle项目中成功使用这个工件。以下是我试图将其联系起来的方式:

dependencies {
   compile group: 'com.example', name: 'my-messaging_2.12', version: '0.1'
}

我觉得我在这里做了很多错事,但如果有人能给我一个提示那就太好了

编辑:我再次尝试,结果略有不同,所以我更新了答案


共 (1) 个答案

  1. # 1 楼答案

    我最近遇到了一个类似的问题,并通过在我的构建中添加mavenLocal()命令解决了这个问题。格雷德尔档案。我不知道你是否有同样的问题,但可能值得做一个完整调试输出的gradle项目的构建,并确认它正试图从你的本地回购中提取