Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version RELEASE is incorrectly transformed when the gradle project is created #1777

Open
jmini opened this issue Mar 25, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@jmini
Copy link
Contributor

jmini commented Mar 25, 2024

Describe the bug

When the latest version is used with RELEASE (to get the latest version of a dependency) the build.gradle file created by jbang edit -b is incorrect.

To Reproduce
Hello.java file used to reproduce it:

///usr/bin/env jbang "$0" "$@" ; exit $?

//DEPS ch.qos.reload4j:reload4j:RELEASE

import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;

public class Hello {
    static final Logger logger = Logger.getLogger(Hello.class);

    public static void main(String... args) {
        BasicConfigurator.configure();
        logger.info("Hello World");
    }
}

Run jbang edit -b Hello.java

In the generated file ~/.jbang/cache/projects/Hello.java_jbang_<hash>/Hello/build.gradle the dependency is marked as:

	implementation 'ch.qos.reload4j:reload4j:RELEASE'
Complete generated build.gradle file

plugins {
	id 'java'
	id 'application'
}

repositories {
	mavenLocal()
	maven {
		url  "https://repo1.maven.org/maven2/"
	}
}

dependencies {
	implementation 'ch.qos.reload4j:reload4j:RELEASE'
}

application {
	mainClass = 'Hello'
}

sourceSets.main.java.srcDirs 'src'
sourceSets.test.java.srcDirs 'src'

Which prevent the project to work well in the IDE.

If you do a gradle run in the mentioned folder, it is failing complaining that the dependency ch.qos.reload4j:reload4j:RELEASE can't be found.

Error log

> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find ch.qos.reload4j:reload4j:RELEASE.
     Searched in the following locations:
       - file:/<user.home>/.m2/repository/ch/qos/reload4j/reload4j/RELEASE/reload4j-RELEASE.pom
       - https://repo1.maven.org/maven2/ch/qos/reload4j/reload4j/RELEASE/reload4j-RELEASE.pom
     Required by:
         project :

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.4/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

Expected behavior

The notation 'ch.qos.reload4j:reload4j:RELEASE' is wrong. It should be 'ch.qos.reload4j:reload4j:latest.release'

See: https://docs.gradle.org/current/userguide/single_versions.html

JBang version
Tested with jbang version 0.115.0

@jmini jmini added the bug Something isn't working label Mar 25, 2024
@jmini
Copy link
Contributor Author

jmini commented Mar 25, 2024

Probably here:

// Turn any URL dependencies into regular GAV coordinates
List<String> depIds = dependencies
.stream()
.map(JitPackUtil::ensureGAV)
.collect(Collectors.toList());
// And if we encountered URLs let's make sure the JitPack repo is available
if (!depIds.equals(dependencies)
&& repositories.stream().noneMatch(r -> DependencyUtil.REPO_JITPACK.equals(r.getUrl()))) {
prj.addRepository(DependencyUtil.toMavenRepo(DependencyUtil.ALIAS_JITPACK));
}
renderTemplate(engine, depIds, fullClassName, baseName, resolvedDependencies, repositories,
templateRef,
arguments,
destination);

Just before renderTemplate(..) (after the first change for jitpack) the depIds List could be inspected and entries ending with :RELEASE could be replaced:
--> <something>:RELEASE to <something>:latest.release

Let me know what you think.

@maxandersen
Copy link
Collaborator

Hmm. Wasn't aware of gradles latest. Notion.

Make sense todo or actually natively support gradles notion.

@jmini
Copy link
Contributor Author

jmini commented Sep 25, 2024

@maxandersen If I want to contribute this to jbang, where should the translation between maven RELEASE to gradle style latest.release be located?

@maxandersen
Copy link
Collaborator

I would start with the place you pointed out in edit as no other place this would be needed afaics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants