常春藤发布:在缓存中找不到文件

时间:2016-01-26 15:38:59

标签: java publish ivy

我正在尝试使用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 file not found in cache但你可以看到我在这里设置缓存ivySettings.setDefaultCache(new File("ivy/cache"));当我去ivy/cache/com/mycompany/MAO时,我看到那里的罐子......任何想法?

0 个答案:

没有答案