jbang icon indicating copy to clipboard operation
jbang copied to clipboard

Version RELEASE is incorrectly transformed when the gradle project is created

Open jmini opened this issue 2 years ago • 4 comments

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 avatar Mar 25 '24 09:03 jmini

Probably here:

https://github.com/jbangdev/jbang/blob/826755c427070d2b69e88256a164658160bbedc6/src/main/java/dev/jbang/cli/Edit.java#L454-L468

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.

jmini avatar Mar 25 '24 10:03 jmini

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

Make sense todo or actually natively support gradles notion.

maxandersen avatar Mar 27 '24 15:03 maxandersen

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

jmini avatar Sep 25 '24 08:09 jmini

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

maxandersen avatar Sep 27 '24 09:09 maxandersen