简体   繁体   English

如何将 grails 3 插件发布到我的本地 nexus 存储库?

[英]How do I publish a grails 3 plugin to my local nexus repo?

Running grails publish-plugin doesn't seem to do anything, and the only documentation I could find was about publishing to bintray.运行grails publish-plugin似乎没有任何作用,我能找到的唯一文档是关于发布到 bintray 的。

[edit:] [编辑:]

I can publish the plugin via gradle publish , but wondered if there was a grails-y way to do it, and wonder what grails publish-plugin actually does:/我可以通过gradle publish发布插件,但想知道是否有 grails-y 的方式来做到这一点,并且想知道grails publish-plugin到底做了什么:/

I figured it out with help from Ryan Vanderwerf at http://rvanderwerf.blogspot.com/2015/07/how-to-publish-grails-3-plugin.html who writes that there are a bunch of spring-boot dependencies that don't have versions in them and that causes gradle to freak out.我在http://rvanderwerf.blogspot.com/2015/07/how-to-publish-grails-3-plugin.htmlRyan Vanderwerf的帮助下弄明白了,他写道有一堆 spring-boot 依赖项它们中没有版本,这会导致 gradle 崩溃。 To workaround it, strip out all dependencies in the pom that doesn't have versions:要解决它,请删除 pom 中没有版本的所有依赖项:

publishing {
    publications {
        mavenJar(MavenPublication) {
            pom.withXml {
                def pomNode = asNode()
                pomNode.dependencyManagement.replaceNode {}

                // simply remove dependencies without a version
                // version-less dependencies are handled with dependencyManagement
                // see https://github.com/spring-gradle-plugins/dependency-management-plugin/issues/8 for more complete solutions
                pomNode.dependencies.dependency.findAll {
                    it.version.text().isEmpty()
                }.each {
                    it.replaceNode {}
                }
            }
            from components.java
        }
    }
    repositories {
        maven {
            credentials {
                username "username"
                password "password"
            }
            url "http://localhost/repo"
        }
    }
}

then you can use grails publish-plugin or gradle publish to publish your plugin然后你可以使用grails publish-plugingradle publish来发布你的插件

related SO question: Grails 3 - How to publish to Artifactory相关 SO 问题: Grails 3 - 如何发布到 Artifactory

In Grails 3.0.11, I use the gradle target publishToMavenLocal for my local development.在 Grails 3.0.11 中,我使用 gradle 目标publishToMavenLocal进行本地开发。 There is also another target publishMavenPublicationToMavenRepository .还有另一个目标publishMavenPublicationToMavenRepository This seems to come from the gradle plugin:这似乎来自 gradle 插件:

apply plugin: 'maven-publish'

Seems to be in the standard plugin build.gradle.似乎在标准插件 build.gradle 中。

(Edit: Adding notes on using local maven). (编辑:添加关于使用本地 maven 的注释)。

After re-reading your question and comment below, I don't think that is what you are looking for.在重新阅读您的问题和下面的评论后,我认为这不是您要找的。 It sounds like you want a normal publish to a repository on your system.听起来您想正常发布到系统上的存储库。 publishMavenPublicationToMavenRepository may handle that. publishMavenPublicationToMavenRepository可以处理这个问题。 What I described above is using the local Maven cache to hold a snapshot of a plugin that you can use on your machine in an application.我上面描述的是使用本地 Maven 缓存来保存插件的快照,您可以在应用程序中使用您的机器。

This works for me when developing a plugin used in my application.在开发我的应用程序中使用的插件时,这对我有用。

I did not create a local repository.我没有创建本地存储库。 The gradle plugin above ( maven-publish ) has a task publishToMavenLocal that will publish the Grails plugin to the local maven cache for local development.上面的 gradle 插件 ( maven-publish ) 有一个publishToMavenLocal任务,它将把 Grails 插件发布到本地 maven 缓存以进行本地开发。

It stores the plugin's.zip file in the.m2 cache directory:它将插件的.zip 文件存储在.m2 缓存目录中:

C:\Users\xyz\.m2\repository\org\whatever\plugins\pluginName\0.3-SNAPSHOT

Then, you can use the plugin in a Grails application on your machine.然后,您可以在计算机上的 Grails 应用程序中使用该插件。

In grails 2.x BuildConfig.groovy在 grails 2.x BuildConfig.groovy 中

grails.project.dependency.distribution = {
    remoteRepository(id: '<repo name>',    url: '<url to your nexus repo>')
}

Then:

grails clean

grails compile 

grails maven-deploy --repository=repo name

In grails 3.x+:在 grails 3.x+ 中:

buildscript {
    repositories {
        mavenLocal()
        ...
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
    }
}
publishing {
    repositories {
        maven {
            credentials {
                username "xyz"
                password "xyz"
            }
            url "http://example.com/nexus/content/repositories/nfb"
        }
    }
}

and finally最后

gradle publish渐变发布

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM