Skip to content

Commit 150f913

Browse files
committed
determine if working with snapshot version of graalpy-maven-plugin when calculating classpath
1 parent 212943c commit 150f913

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import org.graalvm.python.embedding.tools.exec.GraalPyRunner;
6767
import org.graalvm.python.embedding.tools.vfs.VFSUtils;
6868

69-
7069
import static org.graalvm.python.embedding.tools.vfs.VFSUtils.VFS_HOME;
7170
import static org.graalvm.python.embedding.tools.vfs.VFSUtils.VFS_ROOT;
7271
import static org.graalvm.python.embedding.tools.vfs.VFSUtils.VFS_VENV;
@@ -483,7 +482,21 @@ private void runGraalPy(MavenProject project, Log log, String... args) throws Mo
483482
}
484483

485484
private static String getGraalPyVersion(MavenProject project) throws MojoExecutionException {
486-
return getGraalPyArtifact(project).getVersion();
485+
DefaultArtifact a = (DefaultArtifact) getGraalPyArtifact(project);
486+
String version = a.getVersion();
487+
if(a.isSnapshot()) {
488+
// getVersion for a snapshot artefact returns base version + timestamp - e.g. 24.2.0-20240808.200816-1
489+
// and there might be snapshot artefacts with different timestamps in the repository.
490+
// We should use $baseVersion + "-SNAPSHOT" as maven is in such case
491+
// able to properly resolve all project artefacts.
492+
version = a.getBaseVersion();
493+
if(!version.endsWith("-SNAPSHOT")) {
494+
// getBaseVersion is expected to return a version without any additional metadata, e.g. 24.2.0-20240808.200816-1 -> 24.2.0,
495+
// but also saw getBaseVersion() already returning version with -SNAPSHOT suffix
496+
version = version + "-SNAPSHOT";
497+
}
498+
}
499+
return version;
487500
}
488501

489502
private static Artifact getGraalPyArtifact(MavenProject project) throws MojoExecutionException {
@@ -514,9 +527,10 @@ private Set<String> calculateLauncherClasspath(MavenProject project) throws Mojo
514527

515528
// 1.) python-launcher and transitive dependencies
516529
// get the artifact from its direct dependency in graalpy-maven-plugin
530+
getLog().debug("calculateLauncherClasspath based on " + GRAALPY_GROUP_ID + ":" + GRAALPY_MAVEN_PLUGIN_ARTIFACT_ID + ":" + version);
517531
DefaultArtifact mvnPlugin = new DefaultArtifact(GRAALPY_GROUP_ID, GRAALPY_MAVEN_PLUGIN_ARTIFACT_ID, version, "compile", "jar", null, new DefaultArtifactHandler("pom"));
518532
ProjectBuildingResult result = buildProjectFromArtifact(mvnPlugin);
519-
Artifact graalPyLauncherArtifact = result.getProject().getArtifacts().stream().filter(a ->GRAALPY_GROUP_ID.equals(a.getGroupId()) && PYTHON_LAUNCHER_ARTIFACT_ID.equals(a.getArtifactId()) && version.equals(a.getVersion()))
533+
Artifact graalPyLauncherArtifact = result.getProject().getArtifacts().stream().filter(a ->GRAALPY_GROUP_ID.equals(a.getGroupId()) && PYTHON_LAUNCHER_ARTIFACT_ID.equals(a.getArtifactId()))
520534
.findFirst()
521535
.orElse(null);
522536
// python-launcher artifact

0 commit comments

Comments
 (0)