Java ivy发布:在缓存中找不到文件

Java ivy发布:在缓存中找不到文件,java,publish,ivy,Java,Publish,Ivy,我正在尝试使用Java向Artifactory发布一个工件 这是代码 public static void publishToArtifactoryPro(String groupId, String artifactId, String version,

我正在尝试使用Java向Artifactory发布一个工件

这是代码

public static void publishToArtifactoryPro(String groupId,
                                           String artifactId,
                                           String version,
                                           Collection artifacts) throws JarMigrationServiceException{

    // create an ivy instance
    IvySettings ivySettings = new IvySettings();
    ivySettings.setDefaultCache(new File("ivy/cache"));

    // use the biblio resolver, if you consider resolving 
    // POM declared dependencies
    IBiblioResolver br = new IBiblioResolver();
    br.setM2compatible(true);
    br.setUsepoms(true);
    br.setName("ibiblio");
    br.setRoot(Constants.ARTIFACTORY_PRO_RELEASE_LOCAL);

    ivySettings.addResolver(br);
    ivySettings.setDefaultResolver(br.getName());

    Ivy ivy = Ivy.newInstance(ivySettings);

    //you always need to resolve before you can retrieve
    ResolveOptions ro = new ResolveOptions();
    // this seems to have no impact, if you resolve by module descriptor (in contrast to resolve by ModuleRevisionId)
    ro.setTransitive(true);
    // if set to false, nothing will be downloaded
    ro.setDownload(true);

    // 1st create an ivy module (this always(!) has a "default" configuration already)
    DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(
        // give it some related name (so it can be cached)
        ModuleRevisionId.newInstance(
            groupId, 
            artifactId+"-envelope", 
            version
        )
    );

    // 2. add dependencies for what we are really looking for
    ModuleRevisionId ri = ModuleRevisionId.newInstance(
        groupId, 
        artifactId,
        version
    );
    // don't go transitive here, if you want the single artifact
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ri, false, false, false);

    // map to master to just get the code jar. See generated ivy module xmls from maven repo
    // on how configurations are mapped into ivy. Or check 
    // e.g. http://lightguard-jp.blogspot.de/2009/04/ivy-configurations-when-pulling-from.html
    dd.addDependencyConfiguration("default", "master");
    md.addDependency(dd);

    // now resolve
    ResolveReport rr = null;
    try {
        rr = ivy.resolve(md,ro);
        if (rr.hasError()) {
            throw new RuntimeException(rr.getAllProblemMessages().toString());
        }
    } 
    catch (ParseException e) {
        throw new JarMigrationServiceException(e.getMessage(), e);
    } 
    catch (IOException e) {
        throw new JarMigrationServiceException(e.getMessage(), e);
    }

    try {
        ivy.publish(
                ModuleRevisionId.newInstance(groupId, artifactId, version), 
                artifacts, 
                "artifactory-publish", 
                new PublishOptions()
                // this is from the envelop module
                .setConfs(new String[]{"default"})
                );

    } 
    catch (IOException e) {
        throw new JarMigrationServiceException(e.getMessage(), e);
    }
}
以下是错误:

Exception in thread "main" java.lang.IllegalStateException: ivy file not found in cache for com.mycompany#MAO;1.1.2: please resolve dependencies before publishing (ivy/cache/resolved-com.mycompany-MAO-1.1.2.xml)
at org.apache.ivy.core.publish.PublishEngine.publish(PublishEngine.java:105)
at org.apache.ivy.Ivy.publish(Ivy.java:600)
at com.mycompany.is.dt.Utilities.JarMigrationUtility.publishToArtifactoryPro(JarMigrationUtility.java:96)
at com.mycompany.is.dt.controllers.JarMigrationService.main(JarMigrationService.java:29)

所以我很困惑,因为它说在缓存中找不到
ivy文件
,但您可以看到我在这里设置缓存
ivySettings.setDefaultCache(新文件(“ivy/cache”)ivy/cache/com/mycompany/MAO
时,我看到了那里的罐子。。。有什么想法吗?

它找不到此工件的ivy-{version}.xml文件。因为缓存中的每个工件文件夹都包含一个ivy-{version}.xml文件和一个jar文件夹。是的,这解决了这个问题@克里斯·博尔顿你怎么把它修好的?不知道。这是5年前的事了!:)