You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradle引入GitHub项目grid-layout v3.0.0作为依赖的可行方案

引入未发布到Maven仓库的GitHub项目Gradle依赖(grid-layout v3.0.0为例)

问题背景

需要将grid-layout项目的v3.0.0版本作为Gradle依赖引入,但该版本暂未上线Maven仓库,环境为Gradle 8.5、Java 21。

已尝试的失败方案

1. JitPack仓库配置

配置JitPack仓库并尝试多个版本标识,但构建失败:

repositories {
    maven { url "https://jitpack.io" }
}
dependencies {
    implementation 'com.github.appreciated:grid-layout:-SNAPSHOT'
}

曾尝试master-SNAPSHOT、6302f04026等版本,查看JitPack构建日志显示存在构建错误。

2. SourceControl配置

在settings.gradle中配置sourceControl后引入依赖,同样失败:
settings.gradle:

sourceControl {
    gitRepository(URI.create("https://github.com/appreciated/grid-layout.git")) {
        producesModule("com.github.appreciated:grid-layout")
    }
}

build.gradle:

dependencies {
    implementation 'com.github.appreciated:grid-layout:3.0.0'
}

可行替代方案

方法1:本地构建后引入本地Maven依赖

  1. 克隆项目到本地:
git clone https://github.com/appreciated/grid-layout.git
  1. 切换到v3.0.0版本:
git checkout v3.0.0
  1. 执行本地构建并发布到本地Maven仓库:
./gradlew publishToMavenLocal
  1. 在你的项目中添加本地Maven仓库并引入依赖:
repositories {
    mavenLocal()
    // 保留其他已有仓库配置
}
dependencies {
    implementation 'com.github.appreciated:grid-layout:3.0.0'
}

方法2:使用Gradle includeBuild直接引用本地项目

  1. 将项目克隆到你的项目目录下的指定位置(例如ext/grid-layout),并切换到v3.0.0版本
  2. 在根项目的settings.gradle中添加配置:
includeBuild("ext/grid-layout") {
    dependencySubstitution {
        substitute module('com.github.appreciated:grid-layout') using project(':')
    }
}
  1. 在build.gradle中直接引入依赖:
dependencies {
    implementation 'com.github.appreciated:grid-layout'
}

临时解决方案(非最优)

以下是一种自动下载并构建项目的临时配置:

根项目settings.gradle配置:

includeBuild("ext/grid-layout") {
    dependencySubstitution {
        substitute module('com.github.appreciated:vaadin-css-grid') using project(':')
    }
}

grid-layout目录下的build.gradle配置:

plugins {
    id 'java'
    id 'org.ajoberstar.grgit' version '5.2.1'
}

// 导入根项目gradle.properties中的属性
try {
    Properties props = new Properties()
    props.load(new FileInputStream("$rootDir/../../gradle.properties"))
    props.each { prop -> project.ext.setProperty(prop.key, prop.value) }
} catch (exception) {
    throw new InvalidUserDataException("未找到参数: $exception.message")
}
repositories {
    mavenCentral()
    maven {
        url "https://vaadin.com/nexus/content/repositories/vaadin-addons/"
    }
}
// 引入pom.xml中定义的依赖
dependencies {
    implementation "com.vaadin:vaadin:$vaadinVersion"
    implementation "com.vaadin:vaadin-core:$vaadinVersion"
    implementation "org.vaddon:mediaquery:5.0.3"
}

group "com.github.appreciated"
version "3.0.0"

def downloadDir = "$projectDir/build/tmp/"
def generatedClasses = file("$downloadDir/src/main/java")
def generatedResources = file("$downloadDir/src/main/resources")

tasks.register("downloadProject") {
    outputs.dirs downloadDir
    def folder = file(downloadDir)
    doFirst {
        assert folder.exists() || folder.mkdirs()
        grgit.clone(dir: folder, uri: 'https://github.com/appreciated/grid-layout.git')
    }
    onlyIf {
        !folder.exists()
    }
}

sourceSets.main.java.srcDirs += generatedClasses.absolutePath
sourceSets.main.resources.srcDirs += generatedResources.absolutePath
compileJava.dependsOn downloadProject

内容的提问来源于stack exchange,提问作者peter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 08:14:53