Gradle:在自定义独立插件中使用"maven-publish"插件 [英] Gradle: Using 'maven-publish' plugin in custom standalone plugin

查看:553
本文介绍了Gradle:在自定义独立插件中使用"maven-publish"插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我提出第三个问题之后,几乎感觉就像是在发送垃圾邮件,这使我的问题显得那么琐碎.但是我只是在Gradle Docs中找不到针对我的案例的任何帮助,而且关于stackoverflow的其他询问问题也无济于事.

Almost feeling like spamming after my third question, cause my questions seem so trivial. But I just don't find any help in Gradle Docs for my cases and also other asked questions on stackoverflow weren't helping.

这次:我无法在自己的独立自定义插件中使用maven-publish插件.到目前为止,我的插件代码:

This time: I can't use the maven-publish plugin in my own standalone custom plugin. The code of my plugin so far:

package com.sample.gradle;

import org.gradle.api.Project;
import org.gradle.api.Plugin;

public class SampleGradlePlugin implements Plugin<Project> {
    public void apply(Project project) {

        project.apply plugin: 'application'
        project.apply plugin: 'maven-publish'
        project.apply plugin: 'maven'

        project.publishing.publications {
            maven(MavenPublication) {
                groupId project.group
                artifactId project.name
                version=project.version
                from components.java
            }
        }

        project.uploadArchives {
            repositories {
                mavenDeployer {
                    repository(url: project.Repo_Upload_Internal){
                        authentication(userName: project.Repo_Upload_User, password: project.Repo_Upload_Pass)
                    }        
                    snapshotRepository(url: project.Repo_Upload_Snapshot){
                        authentication(userName: project.Repo_Upload_User, password: project.Repo_Upload_Pass)
                    }
                }
            }
        }
        //this try/catch is not important for my question
        try{
            project.repositories {
                maven {
                    url project.Repo_Gp_Internal
                    credentials {
                        username project.Repo_Gp_User;
                    }
                }
            }
        }
        catch(MissingPropertyException e){
            println "Info: '"+e.getProperty()+"' not declared in \\"+project.name+"\\gradle.properties"
        }
    }
}

publishing闭包是在我的一个项目中使用插件时给我带来此错误的重要部分:

The publishing closure is the important part that brings me this error, when I use my plugin in one of my projects:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\quastc\Desktop\Gradle_Projects\Application_RootProject\buil
d.gradle' line: 3

* What went wrong:
A problem occurred evaluating root project 'Application_RootProject'.
> Failed to apply plugin [id 'sample.sample-groovy-plugin']
   > Cannot create a Publication named 'MavenPublication' because this container
 does not support creating elements by name alone. Please specify which subtype
of Publication to create. Known subtypes are: MavenPublication

我的错误在哪里?我忘记了什么?

Where's my mistake? What did I forget?

如果有人回答,请告诉我您如何获得知识.

If somebody answers, PLEASE let me know HOW you got your knowledge.

推荐答案

找到了适用于我的解决方案.我不再使用maven-publish插件.只是maven插件.然后,将这段代码放在我自己的插件的末尾:

Found a solution that works for me right now. I don't use the maven-publish plugin anymore. Just the maven plugin. Then I put this code at the end of my own plugin:

    project.configurations {
        deployerJars 
    }
    project.dependencies {
        deployerJars "org.apache.maven.wagon:wagon-http:2.2"
    }   
    project.uploadArchives {
        repositories {
            mavenDeployer {
                repository(url: project.Repo_Upload_Internal){
                    authentication(userName: project.Repo_Upload_User, password: project.Repo_Upload_Pass)
                }        
                snapshotRepository(url: project.Repo_Upload_Snapshot){
                    authentication(userName: project.Repo_Upload_User, password: project.Repo_Upload_Pass)
                }
            }
        }
    }

进一步:

我还没有找到禁止上传zip和tar文件的方法.我仍然需要几个build.gradle文件中的一些复制和粘贴代码来完成此工作.就是这样的代码:

I haven't found a way to suppress the uploading of a zip and a tar file. I still need some copy&paste code in the several build.gradle files to do this job. It's this code:

configurations.archives.with {
    artifacts.remove artifacts.find { it.archiveTask.is distZip }
    artifacts.remove artifacts.find { it.archiveTask.is distTar }
}

我尚无法更改该代码以在我的自定义插件中使用.

I'm not able to change that code to work in my custom plugin yet.

这篇关于Gradle:在自定义独立插件中使用"maven-publish"插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆