首页 文章

Ant Ivy conf特定检索在我发布的jar上失败了

提问于
浏览
0

使用Ant Ivy构建,我正在尝试将我的 jar 分成一个用于第三方 jar 的配置和我构建和发布的 jar 的另一个配置 . ProjectA使用第三方jar并构建一个ProjectB依赖的jar,但是当我使用Ant Ivy confs时,我无法让ProjectB检索ProjectA jar .

当我为ProjectB执行ant脚本时,它可以很好地构建ProjectA . ProjectA构建将jar发布到本地存储库 . ProjectB从公共存储库中检索必要的jar没有问题,但是当它尝试检索ProjectA jar时,它表示UNRESOLVED DEPENDENCY:testproject#ProjectA; 2.0.0:testproject#ProjectA中找不到配置; 2.0.0:'localjars' . 它来自testproject#ProjectB; 2.0.0 localjars

如果我删除对第二个配置的所有引用,localjars,并且只使用默认的一切,它工作正常 . 我真的需要把我的 jar 分成不同的混蛋 .

我已成功使用从ant脚本传递的修订值代替下面的“2.0.0”并使用$ 引用,但conf错误是相同的 .

ProjectA ivy.xml(为简洁起见,依赖于子集):

<ivy-module version="2.0">
    <info organisation="testproject" module="ProjectA" revision="2.0.0" status="release" publication="20160524124555"/>
<configurations> 
    <conf name="default" transitive="false" visibility="public"/>
    <conf name="localjars" extends="default" visibility="public"/>
</configurations> 

<publications>
     <artifact name="projectA-jar-2.0.0" type="jar" conf="localjars" ext="jar"/>
</publications>

<dependencies>
    <dependency org="commons-beanutils" name="commons-beanutils" rev="1.7.0" conf="default->master"/>
    <dependency org="commons-collections" name="commons-collections" rev="3.1" conf="default->master"/>
</dependencies>
</ivy-module>

ProjectA build.xml发布目标:

<target name="publish" depends="package"
    description="--> compile test   and publish this project in the local ivy repository">
    <ivy:publish artifactspattern="${DEPLOY_DIR_LIB}/[artifact].[ext]"
        resolver="local" pubrevision="2.0.0" status="release"
        srcivypattern="${ivy.dep.file}" forcedeliver="true" overwrite="true" conf="localjars,default"/>

    <echo message="project ${ant.project.name} released with version 2.0.0" />
</target>

ProjectB ivy.xml:

<ivy-module version="2.0">
<info organisation="testproject" module="ProjectB" revision="2.0.0" status="release" publication="20160524103113"/>
<configurations> 
    <conf name="default"/> 
    <conf name="localjars" extends="default"/>
</configurations> 

<publications>
    <artifact name="projectB-2.0.0" conf="localjars" type="jar" ext="jar"/>
</publications>

<dependencies>
    <dependency org="testproject" name="ProjectA" rev="${revision}" transitive="true" conf="localjars->localjars; default->default"/>
</dependencies>

ProjectB Ant解析目标:

<target name="resolve" description="--> retrieve dependencies with ivy">
    <ivy:retrieve pattern="${DEPLOY_DIR_LIB}/[artifact]-2.0.0.[ext]" revision="2.0.0" conf="localjars" />
</target>

知道什么是错的吗?谢谢!

帕特里克

1 回答

  • 0

    不完全确定您的配置无法正常工作的原因 . 我建议的一件事是不要禁用传递依赖 . 您会注意到我在下面的工作示例中创建“默认”配置有不同的方法 .

    示例

    每个项目都有自己的本地构建和常 Spring 藤文件 . 协作是通过发布到“本地”存储库的jar .

    ├── build.xml
    ├── ProjectA
    │   ├── build.xml
    │   ├── ivy.xml
    │   └── src
    │       └── Hello.txt
    └── ProjectB
        ├── build.xml
        ├── ivy.xml
        └── src
            └── Hello.txt
    

    build.xml

    使用buildlist任务以正确顺序构建所有模块的主构建文件 .

    此外,我通常还包括安装常 Spring 藤的额外目标 .

    <project name="main" default="publish" xmlns:ivy="antlib:org.apache.ivy.ant">
    
      <available classname="org.apache.ivy.Main" property="ivy.installed"/> 
    
      <target name="install-ivy" unless="ivy.installed">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
        <fail message="Ivy has been installed. Run the build again"/>
      </target>
    
      <target name="publish" depends="install-ivy">
        <ivy:buildlist reference="build-path">
          <fileset dir="." includes="*/build.xml"/>
        </ivy:buildlist>
    
        <subant target="publish" buildpathref="build-path"/>
      </target>
    
      <target name="clean">
        <subant target="clean">
          <fileset dir="." includes="*/build.xml"/>
        </subant>
      </target>
    
      <target name="clean-all" depends="clean">
        <ivy:cleancache/>
      </target>
    
    </project>
    

    ProjectA / ivy.xml

    "master"配置仅包含工件 . 这个命名约定反映了scopes used by Maven .

    另请注意“默认”配置如何扩展“主”和“运行时” . 这使客户能够下载他们需要的一切 .

    <ivy-module version="2.0">
      <info organisation="com.myspotontheweb" module="ProjectA"/>
    
      <configurations>
        <conf name="default" description="Master artifact and runtime dependencies" extends="master,runtime"/>
        <conf name="master"  description="Artifact published by this module"/>
        <conf name="compile" description="Required to compile application"/>
        <conf name="runtime" description="Additional run-time dependencies" extends="compile"/>
        <conf name="test"    description="Required for test only" extends="runtime"/>
      </configurations>
    
      <publications>
        <artifact name="ProjectA" type="jar" ext="jar" conf="master"/>
      </publications>
    
      <dependencies>
        <!-- compile dependencies -->
        <dependency org="org.slf4j" name="slf4j-api" rev="1.7.5" conf="compile->default"/>
    
        <!-- runtime dependencies -->
        <dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.5" conf="runtime->default"/>
    
        <!-- test dependencies -->
        <dependency org="junit" name="junit" rev="4.11" conf="test->default"/>
      </dependencies>
    
    </ivy-module>
    

    ProjectB / ivy.xml

    请注意ProjectA是唯一的依赖项,它将远程“默认”配置映射到本地“编译”配置 .

    另一个微妙的问题是使用“latest.integration”动态修订版 . 这意味着我们不需要对ProjectA的修订进行硬编码 .

    <ivy-module version="2.0">
      <info organisation="com.myspotontheweb" module="ProjectB"/>
    
      <configurations>
        <conf name="default" description="Master artifact and runtime dependencies" extends="master,runtime"/>
        <conf name="master"  description="Artifact published by this module"/>
        <conf name="compile" description="Required to compile application"/>
        <conf name="runtime" description="Additional run-time dependencies" extends="compile"/>
        <conf name="test"    description="Required for test only" extends="runtime"/>
      </configurations>
    
      <publications>
        <artifact name="ProjectB" type="jar" ext="jar" conf="master"/>
      </publications>
    
      <dependencies>
        <dependency org="com.myspotontheweb" name="ProjectA" rev="latest.integration" conf="compile->default"/>
      </dependencies>
    
    </ivy-module>
    

    ProjectA / build.xml

    要发布的修订版本设置为属性,必要时可以覆盖该属性 .

    另请注意,如何使用cachepath任务将常 Spring 藤配置用于控制构建中的类路径

    <project name="ProjectA" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
    
      <property name="build.dir"    location="build"/>
      <property name="pub.version"  value="1.0"/>
      <property name="pub.resolver" value="local"/>
    
      <target name="resolve">
        <ivy:resolve/>
        <ivy:cachepath pathid="compile.path" conf="compile"/>
        <ivy:cachepath pathid="test.path"    conf="test"/>
      </target>
    
      <target name="build" depends="resolve">
        <mkdir dir="${build.dir}"/>
        <jar destfile="${build.dir}/${ant.project.name}.jar" basedir="src"/>
      </target>
    
      <target name="publish" depends="build">
        <ivy:publish pubrevision="${pub.version}" resolver="${pub.resolver}" overwrite="true">
          <artifacts pattern="${build.dir}/[artifact].[ext]"/>
        </ivy:publish>
      </target>
    
      <target name="clean">
        <delete dir="${build.dir}"/>
      </target>
    
    </project>
    

    ProjectB / build.xml

    与具有不同名称属性的其他项目相同 .

    <project name="ProjectB" default="build" ....
    

相关问题