如何创建一个Gradle构建文件,正确地将Java项目发布到包含源的Ivy仓库?

时间:2013-11-19 16:51:50

标签: java gradle ivy

首先:我已经在SO,谷歌,Gradle文档等方面找到了很多这方面的信息,它让我头疼,但没有一个单一来源告诉我正确将带有源的普通旧java项目发布到Ivy存储库,使用正确的配置,maven分类器,常春藤类型等等。这就是我所得到的:

apply plugin: 'java'
apply plugin: 'ivy-publish'

group 'com.example'
version '0.1.0'

repositories {
    ivy {
        name 'local'
        url "${System.properties['user.home']}/localivy"
    }
}

task sourceJar(type: Jar) {
    from sourceSets.main.java
    // If the classifier isn't put here, the source jar overwrites the compiled jar
    classifier "sources"
}

publishing {
    publications {
        ivy(IvyPublication) {
            configurations {
                sources {}
            }
            from components.java
            descriptor.status = 'release'
            artifact(sourceJar) {
                type "source"
                conf "sources"
            }
        }
    }
    repositories {
        add project.repositories.local
    }
}

这给了我以下错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':publishIvyPublicationToLocalRepository'.
> Failed to publish publication 'ivy' to repository 'local'
   > Could not parse Ivy file file:/Users/markus/code/publish-test/build/publications/ivy/ivy.xml
      > Problem occurred while parsing ivy file: Cannot add artifact 'publish-test.jar(source)' to configuration 'sources' of module com.example#publish-test;0.1.0 because this configuration doesn't exist!

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.  

具体来说,我试图在运行时配置中没有源代码(因为获取库的客户端然后获取源代码,即使它们只需要编译依赖项)。

另外,我有点困惑的是,发布源代码(以及javadocs)并不是 java Gradle插件的标准部分,就像发布已编译的jar一样。

那里的人有什么帮助吗?谢谢!

PS:我的参考ivy.xml文件来自Google Guava 15.0:

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
    <info organisation="com.google.guava"
        module="guava"
        revision="15.0"
        status="release"
        publication="20130906215249"
    >
        <description homepage="">
        Guava is a suite of core and expanded libraries that include
    utility classes, google&apos;s collections, io classes, and much
    much more.

    Guava has two code dependencies - javax.annotation
    per the JSR-305 spec and javax.inject per the JSR-330 spec.
        </description>
        <m:dependency.management__org.easymock__easymock__scope>test</m:dependency.management__org.easymock__easymock__scope>
        <m:dependency.management__com.google.caliper__caliper__scope>test</m:dependency.management__com.google.caliper__caliper__scope>
        <m:dependency.management__junit__junit__scope>test</m:dependency.management__junit__junit__scope>
        <m:dependency.management__org.truth0__truth__scope>test</m:dependency.management__org.truth0__truth__scope>
        <m:properties__test.include>**/*Test.java</m:properties__test.include>
        <m:properties__gpg.skip>true</m:properties__gpg.skip>
        <m:dependency.management__org.mockito__mockito-core__scope>test</m:dependency.management__org.mockito__mockito-core__scope>
        <m:properties__truth.version>0.13</m:properties__truth.version>
        <m:properties__project.build.sourceEncoding>UTF-8</m:properties__project.build.sourceEncoding>
        <m:dependency.management__javax.inject__javax.inject__version>1</m:dependency.management__javax.inject__javax.inject__version>
        <m:dependency.management__org.truth0__truth__exclusion_0>com.google.guava__guava</m:dependency.management__org.truth0__truth__exclusion_0>
        <m:dependency.management__junit__junit__version>4.8.2</m:dependency.management__junit__junit__version>
        <m:dependency.management__com.google.caliper__caliper__version>0.5-rc1</m:dependency.management__com.google.caliper__caliper__version>
        <m:dependency.management__com.google.caliper__caliper__exclusion_0>com.google.guava__guava</m:dependency.management__com.google.caliper__caliper__exclusion_0>
        <m:dependency.management__org.truth0__truth__version>0.13</m:dependency.management__org.truth0__truth__version>
        <m:dependency.management__com.google.code.findbugs__jsr305__version>1.3.9</m:dependency.management__com.google.code.findbugs__jsr305__version>
        <m:properties__sonatypeOssDistMgmtSnapshotsUrl>https://oss.sonatype.org/content/repositories/snapshots/</m:properties__sonatypeOssDistMgmtSnapshotsUrl>
        <m:dependency.management__org.easymock__easymock__version>3.0</m:dependency.management__org.easymock__easymock__version>
        <m:dependency.management__org.mockito__mockito-core__version>1.8.5</m:dependency.management__org.mockito__mockito-core__version>
        <m:maven.plugins>org.apache.maven.plugins__maven-enforcer-plugin__1.0|org.apache.maven.plugins__maven-enforcer-plugin__1.0|null__maven-gpg-plugin__1.4|org.apache.maven.plugins__maven-enforcer-plugin__1.0|org.apache.maven.plugins__maven-enforcer-plugin__1.0|null__maven-gpg-plugin__1.4|org.apache.felix__maven-bundle-plugin__2.3.7|null__maven-compiler-plugin__null|null__maven-source-plugin__null|null__maven-dependency-plugin__null|org.codehaus.mojo__animal-sniffer-maven-plugin__null|org.apache.maven.plugins__maven-javadoc-plugin__null</m:maven.plugins>
    </info>
    <configurations>
        <conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf" extends="runtime,master"/>
        <conf name="master" visibility="public" description="contains only the artifact published by this module itself, with no transitive dependencies"/>
        <conf name="compile" visibility="public" description="this is the default scope, used if none is specified. Compile dependencies are available in all classpaths."/>
        <conf name="provided" visibility="public" description="this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive."/>
        <conf name="runtime" visibility="public" description="this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath." extends="compile"/>
        <conf name="test" visibility="private" description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases." extends="runtime"/>
        <conf name="system" visibility="public" description="this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository."/>
        <conf name="sources" visibility="public" description="this configuration contains the source artifact of this module, if any."/>
        <conf name="javadoc" visibility="public" description="this configuration contains the javadoc artifact of this module, if any."/>
        <conf name="optional" visibility="public" description="contains all optional dependencies"/>
    </configurations>
    <publications>
        <artifact name="guava" type="bundle" ext="jar" conf="master"/>
        <artifact name="guava" type="source" ext="jar" conf="sources" m:classifier="sources"/>
        <artifact name="guava" type="javadoc" ext="jar" conf="javadoc" m:classifier="javadoc"/>
    </publications>
    <dependencies>
        <dependency org="com.google.code.findbugs" name="jsr305" rev="1.3.9" force="true" conf="optional->compile(*),master(*)"/>
        <dependency org="javax.inject" name="javax.inject" rev="1" force="true" conf="optional->compile(*),master(*)"/>
        <override org="org.easymock" module="easymock" matcher="exact" rev="3.0"/>
        <override org="org.truth0" module="truth" matcher="exact" rev="0.13"/>
        <override org="com.google.caliper" module="caliper" matcher="exact" rev="0.5-rc1"/>
        <override org="org.mockito" module="mockito-core" matcher="exact" rev="1.8.5"/>
        <override org="javax.inject" module="javax.inject" matcher="exact" rev="1"/>
        <override org="junit" module="junit" matcher="exact" rev="4.8.2"/>
        <override org="com.google.code.findbugs" module="jsr305" matcher="exact" rev="1.3.9"/>
    </dependencies>
</ivy-module>

0 个答案:

没有答案