2012-04-11 137 views
1

我正在嘗試使用ivy與ant將我的項目工件發佈到nexus sonatype存儲庫。 使用三個文件: 1> - build.xml文件使用常春藤和螞蟻將jar添加到nexus sonatype repo

<project name="abc" basedir="." 

default="create-jar" xmlns:ivy="antlib:org.apache.ivy.ant"> 

<property name="build.dir" value="classes"/> 

<property name="src.dir" value="src"/> 

<property name="webinf.dir" value="../WEB-INF"/> 

<property name="weblib.dir" value="${webinf.dir}/lib"/> 

<path id="master-classpath"> 

<fileset dir="${weblib.dir}"> 

<include name="*.jar"/> 

</fileset> 

</path> 

<target name="clean" description="Clean output dirs (build, weblib, dist)"> 

<delete dir="${build.dir}"/> 

<mkdir dir="${build.dir}"/> 

<delete dir="dist"/> 

<mkdir dir="dist"/> 

</target> 

<target name="create-jar" depends="clean"> 

<javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true" nowarn="true"> 

<classpath refid="master-classpath"/> 

<src path="${src.dir}"/> 

</javac> 

<jar destfile="dist/mws-pojos.jar" basedir="${build.dir}"/> 

</target> 

<target name="prepare" description="Generate POM" depends="create-jar"> 

<!-- Optional: Intermediate file containing resolved version numbers --> 

<!--ivy:deliver deliverpattern="${build.dir}/ivy.xml" pubrevision="${publish.revision}" status="release"/--> 
<!-- Generate the Maven POM --> 
<ivy:makepom ivyfile="ivy.xml" pomfile="test.pom"/> 
</target> 
<target name="resolve" description="retreive dependencies with ivy" 
depends="publish"> 
<ivy:retrieve /> 
</target> 
<target name="publish" depends="prepare,create-jar" 
description="Upload to Nexus"> 
<ivy:publish organisation="my.org" module="mws-pojos" 
revision="1.0" resolver="nexus-deploy" 
pubrevision="${publish.revision}"    
overwrite="true" publishivy="false" > 
<artifacts pattern="${build.dir}/[artifact](-[classifier]).[ext]"/> 
</ivy:publish> 
</target> 
</project> 

2 - >的ivy.xml

<ivy-module version='2.0' xmlns:e="http://ant.apache.org/ivy/extra"> 
<info organisation="my.org" module="mws-pojos" revision="1.0"/> 
<publications> 
<artifact name="mws-pojos" type="jar" e:classifier="disto"/> 
</publications> 
</ivy-module> 

3 - > ivysettings.xml

<ivysettings> 
<settings defaultResolver="nexus-central"/> 
<credentials host="http://somehost/nexus" realm="Sonatype Nexus Repository Manager" username="user1" passwd="deploy"/> 
<resolvers> 
<ibiblio name="nexus-central" root="http://somehost/nexus/content/repositories/central/" m2compatible="true"/> 
<ibiblio name="nexus-deploy" root="http://somehost/nexus/content/repositories/repo" m2compatible="true"/> 
</resolvers> 
</ivysettings> 

但在compillation它給出以下錯誤:

BUILD FAILED 

/home/someuser/mobilewebservice/mws-pojos/build.xml:40: impossible to publish artifacts for mmt#mws-pojos;1.0: java.lang.IllegalStateException: ivy file not found in cache for mmt#mws-pojos;1.0: please resolve dependencies before publishing (/home/someuser/.ivy2/cache/resolved-mmt-mws-pojos-1.0.xml) 

at org.apache.ivy.core.publish.PublishEngine.publish(PublishEngine.java:105) 

at org.apache.ivy.Ivy.publish(Ivy.java:600) 

at org.apache.ivy.ant.IvyPublish.doExecute(IvyPublish.java:311) 

at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:277) 

at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 

回答

1

您發佈之前需要一個額外的resolve

<ivy:resolve>...</ivy:resolve> 

相關問題