eclipse-tycho / tycho

Tycho project repository (tycho)
https://tycho.eclipseprojects.io
Eclipse Public License 2.0
166 stars 189 forks source link

'version' contains an expression but should be a constant #1806

Closed henryju closed 1 year ago

henryju commented 1 year ago

Hi,

I am trying to use the new CI friendly feature of Tycho 3.0.0.

Seems to work, but I get this annoying warning:

./mvnw clean verify
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for org.sonarsource.sonarlint.eclipse:org.sonarlint.eclipse.core:eclipse-plugin:7.6.0-SNAPSHOT
[WARNING] 'version' contains an expression but should be a constant. @ org.sonarsource.sonarlint.eclipse:sonarlint-eclipse-parent:7.6.0${qualifier}, /home/julien.henry/Projects/sonarlint/sonarlint-eclipse/pom.xml, line 15, column 12

Assuming it is a false positive, is there a way to silent this warning?

laeubi commented 1 year ago

If you can provide an integration-test to demonstrate the issue we can investigate this.

In general:

henryju commented 1 year ago

Tycho must be enabled as a build extension in extensions.xml

Indeed, I missed this part of the release notes. Thanks for pointing that.

I tried to do it the way it is mentioned (putting Tycho version in a centralized place in .mvn/maven.config) but now it seems it is preventing m2e to resolve the Tycho version. After some search, it seems you are already aware :) https://github.com/eclipse-m2e/m2e-core/issues/274

Another problem I am facing with this "ci friendly" feature, is that it doesn't seem to work when deploying to Artifactory with the maven-artifactory-plugin. I have configured the version in the pom.xml to be X.Y.Z${qualifier}. I want the qualifier to be a build number provided by my CI, so I run:

mvn deploy -DforceContextQualifier=58175

but all artifacts are still deployed with the -SNAPSHOT version.

[...]
[INFO] --- tycho-packaging-plugin:3.0.0:build-qualifier-aggregator (default-build-qualifier-aggregator) @ org.sonarlint.eclipse.site ---
[INFO] The project's OSGi version is 7.6.0.58175
[...]
[INFO] --- maven-install-plugin:3.0.0-M1:install (default-install) @ org.sonarlint.eclipse.site ---
[INFO] Installing /home/vsts/work/1/s/org.sonarlint.eclipse.site/target/org.sonarlint.eclipse.site-7.6.0-SNAPSHOT.zip to /home/vsts/work/1/.m2/repository/org/sonarsource/sonarlint/eclipse/org.sonarlint.eclipse.site/7.6.0-SNAPSHOT/org.sonarlint.eclipse.site-7.6.0-SNAPSHOT.zip
[INFO] Installing /home/vsts/work/1/s/org.sonarlint.eclipse.site/pom.xml to /home/vsts/work/1/.m2/repository/org/sonarsource/sonarlint/eclipse/org.sonarlint.eclipse.site/7.6.0-SNAPSHOT/org.sonarlint.eclipse.site-7.6.0-SNAPSHOT.pom
[...]
[INFO] --- maven-deploy-plugin:3.0.0-M1:deploy (default-deploy) @ org.sonarlint.eclipse.site ---
[INFO] Skipping artifact deployment
[...]
[INFO] [pool-33-thread-1] Deploying artifact: https://my.company.artifactory/org/sonarsource/sonarlint/eclipse/org.sonarlint.eclipse.site/7.6.0-SNAPSHOT/org.sonarlint.eclipse.site-7.6.0-SNAPSHOT.zip
[ERROR] Failed to upload file

From what I understand, the artifactory plugin will somehow disable the regular Maven deploy plugin, in order to deploy all artifacts at once, at the end of the build. Maybe the "ci friendly" version if not correctly computed here? Or maybe I am again missing something...

Any idea?

laeubi commented 1 year ago

${qualifier} works a bit different here, it actually makes the value of the qualifier used for bundle computation available to maven, you can see an example here: https://github.com/eclipse-equinox/p2/blob/master/pom.xml

to actually set the qualifer you usually provide a format string like -Dtycho.buildqualifier.format=yyyyMMddHHmm if you like a constant string you need to use another variable (e.g. ${revision}) and specify -DforceContextQualifier=58175 -Drevision=58175. But I think one might be able to add support for forceContextQualifier, the best would be to provide an integration-test to demonstrate the issue.

henryju commented 1 year ago

This comment says I could use -Dqualifier=xxx to pass a constant value. But I think I tried that and it was producing a version with "double" qualifier: something like a.b.c.xxx.timestamp.

But ok, I will try to build a reproducer.

laeubi commented 1 year ago

This comment says I could use -Dqualifier=xxx to pass a constant value. But I think I tried that and it was producing a version with "double" qualifier: something like a.b.c.xxx.timestamp.

This is all a bit experimental and only partly covered by integration test, so its likely there are some issues. So we are happy about all feedback and testing to hardening that feature.

laeubi commented 1 year ago

@henryju do you maybe like to enhance the CIFirendlyversion test with your example?

https://github.com/eclipse-tycho/tycho/blob/master/tycho-its/src/test/java/org/eclipse/tycho/test/buildextension/CiFriendlyVersionsTest.java https://github.com/eclipse-tycho/tycho/tree/master/tycho-its/projects/ci-friendly/