通过自定义插件在gradle中创建默认项目Jar



我正在为gradle构建我的第一个自定义插件。这个插件可以做很多事情,包括根据项目的其他插件来配置它所应用的项目。我想让这个插件做的一件事是处理Maven的所有发布工作,这样它就不需要出现在每个build.gradle中。每个构建都做完全相同的事情,它们只有它们的源Jar和它们的基础项目Jar,并且它们都被(或将被)发布到我们的工件存储库中。

可以了,我可以创建Jar文件了。但是,Jar文件只包含META-INF文件夹和清单文件,而不包含项目的任何类。有人遇到过这个问题并知道原因吗?

   // Configure Jar Manifest
    jar {
        manifest = project.manifest {
            from sharedManifest
        }
    }
    // Configure sources Jar manifest
    (project.getTasks()).create("sourcesJar", Jar) {
        classifier "sources"
        from project.sourceSets.main.allSource
        manifest = project.manifest {
            from sharedManifest
        }
    }
    artifacts {
        archives project.tasks.sourcesJar
    }
    publishing {
        publications {
            mavenJava(MavenPublication) {
                from project.components.java
                artifact project.tasks.sourcesJar
                pom.withXml {
                    def root = asNode()
                    root.appendNode("name", project.name)
                    root.appendNode("description", project.name + "component of company.")
                    root.appendNode("inceptionYear", "2010")
                }
            }
        }
        repositories {
            maven {
                //We only publish to the Releases repository if the project is given the property "release"
                if(project.hasProperty("release")) {
                    url "http://clipped/"
                } else {
                    url "http://clipped/"
                }
                credentials {
                    if(project.hasProperty("nexusUsername") && project.hasProperty("nexusPassword"))
                    {
                        username = nexusUsername
                        password = nexusPassword
                    }
                }
            }
        }
    }

就是这样,Peter,一个开发人员把所有调用这个插件的项目从src/main/java移到了src/java,认为文件夹结构太深了。插件代码没有问题

最新更新