How to fetch the latest version of a gradle task input from nexus?

Hi all,

I have a gradle task written in Java which takes some versioned artifact deployed in nexus as an input. The important part is, I always need to have the latest version of this artifact. I still couldn’t get that part working.

I tried using com.pro.cod.news:news-archive:+ like this.

NamedDomainObjectProvider<Configuration> customConfigProvider =
        project.getConfigurations().register(
                        FETCH_TEXT_FILE_ZIP_TASK_CONFIG,
                        c -> {
                            c.extendsFrom(project.getConfigurations().getByName("runtimeOnly"));
                            c.setCanBeResolved(true);
                            c.setCanBeConsumed(false);
                });
taskProvider.configure(
        task -> {
            Configuration customConfig = customConfigProvider.get();
            project.getDependencies()
                   .add(FETCH_TEXT_FILE_ZIP_TASK_CONFIG, "com.pro.cod.news:news-archive:+");

But it failed with the following error.

Could not find any matches for com.pro.cod.news:news-archive:+ as no versions of com.pro.cod.news:news-archive are available

It works fine when I use a fixed version like com.pro.cod.news:news-archive:390.

What should I do to fetch the latest version? Any ideas are really appreciated.

Assuming you are talking about a Maven repository in Nexus.
Iirc the dynamic version resolution retrieves the maven-metadata.xml for the dependency to get the list of versions.
So my guess would be that this file is missing or not accessible or not maintained properly.

Thanks for the answer. I checked the Nexus and I can see the maven-metadata.xml file with all correct versions in it.

Can you think of anything I should try from the gradle config side? Or do you think this is not an issue in the gradle side?

I tried your code with commons-lang:commons-lang:+ on mavenCentral() and it worked fine.

Alright. I unfortunately can’t try that as I can’t access mavenCentral() directly in my company network. But this helps. I will check with our dev-ops if they have disabled this from maybe at nexus level. Thanks.

1 Like