Gradle install命令以使用version和groupId在本地发布

时间:2018-10-23 20:15:50

标签: gradle java-8 gradle-plugin

我正在尝试获取一个Java / Gradle项目来构建一个共享/不可执行的JAR并将其发布到我的本地Maven存储库中(以便我可以将其拉到我在本地工作的其他项目中)。

我的build.gradle

plugins {
    id 'java'
    id 'maven'
}

version = '0.0.1-SNAPSHOT'
group = 'mygroup'
rootProject.name = 'myproject'

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    compile(
        'ch.qos.logback:logback-classic:1.2.3'
        ,'org.apache.commons:commons-lang3:3.7'
    )

    testCompile(
        'junit:junit:4.12'
        ,'org.mockito:mockito-core:2.23.0'
    )
}

test {
    // Trick to run tests in parallel with as much concurrency as possible.
    maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}

jar {
    baseName = rootProject.name
}

以及我如何调用它:

./gradlew clean build install

在文件系统上,我看到一个/home/.m2/repository/myproject/unspecified/目录(myrpoject是我的项目的名称,并且是正确的),其中包含:

  • myproject.jar;和
  • myproject.pom

很亲密!我只是想弄清楚用我配置的值(unspecified替换0.0.1-SNAPSHOT版本号,以及如何将安装目录更改为/home/.m2/repository/mygroup/myproject/unspecified/(请注意{{1 }}!)?

1 个答案:

答案 0 :(得分:2)

这是文件的外观:

gradle.properties

version=0.0.1-SNAPSHOT
group=mygroup

settings.gradle

rootProject.name = 'myproject'

build.gradle

plugins {
    id 'java'
    id 'maven'
}

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    compile(
        'ch.qos.logback:logback-classic:1.2.3'
        ,'org.apache.commons:commons-lang3:3.7'
    )

    testCompile(
        'junit:junit:4.12'
        ,'org.mockito:mockito-core:2.23.0'
    )
}

test {
    maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}

jar {
    baseName = rootProject.name
}