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

Proper way of using a Maven toolchain? #617

Open
LorenzoBettini opened this issue Apr 4, 2024 · 7 comments
Open

Proper way of using a Maven toolchain? #617

LorenzoBettini opened this issue Apr 4, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@LorenzoBettini
Copy link
Contributor

This action generates a toolchains.xml file in .m2/toolchains.xml according to the arguments passed to the setup action; however, Maven (its toolchain plugin) does not seem to detect the needed information.

In my workflow I have (runs-on: ubuntu-latest):

      - name: 'Set up Java'
        uses: actions/setup-java@v4
        with:
          java-version: 21
          distribution: 'temurin'

      - name: Show Toolchain
        run: cat ~/.m2/toolchains.xml

which seems to work as expected:

Run actions/setup-java@v4
  with:
    java-version: 21
    distribution: temurin
    java-package: jdk
    check-latest: false
    server-id: github
    server-username: GITHUB_ACTOR
    server-password: GITHUB_TOKEN
    overwrite-settings: true
    job-status: success
    token: ***
Installed distributions
  Resolved Java 21.0.2+13 from tool-cache
  Setting Java 21.0.2+13 as the default
  Creating toolchains.xml for JDK version 21 from temurin
  Writing to /home/runner/.m2/toolchains.xml
  
  Java configuration:
    Distribution: temurin
    Version: 21.0.2+13
    Path: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.2-13/x64
...
Run cat ~/.m2/toolchains.xml
<?xml version="1.0"?>
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>21</version>
      <vendor>temurin</vendor>
      <id>temurin_21</id>
    </provides>
    <configuration>
      <jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.2-13/x64</jdkHome>
    </configuration>
  </toolchain>
</toolchains>

Then, in my Maven POM I have this profile, which is correctly activated:

<profile>
	<id>strict-jdk-21</id>
	<activation>
		<jdk>[21,)</jdk>
	</activation>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-toolchains-plugin</artifactId>
				<version>3.1.0</version>
				<executions>
					<execution>
						<goals>
							<goal>toolchain</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<toolchains>
						<jdk>
							<version>21</version>
							<vendor>temurin</vendor>
							<id>temurin_21</id>
						</jdk>
					</toolchains>
				</configuration>
			</plugin>
		</plugins>
	</build>
</profile>

However, during the build the plugin doesn't seem to find the toolchain:

[INFO] Required toolchain: jdk [ vendor='temurin' id='temurin_21' version='21' ]
[DEBUG] Toolchain JDK[/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.10-7/x64] doesn't match required property: id
Error:  No toolchain matched from 1 found for type jdk
Error:  Cannot find matching toolchain definitions for the following toolchain types:
jdk [ vendor='temurin' id='temurin_21' version='21' ]

It looks like it ignores the generated toolchains since it refers to JDK 17, which is never mentioned in my workflow.

Am I doing anything wrong?

@aparnajyothi-y
Copy link
Contributor

Hello @LorenzoBettini, Thank you for creating the issue and we will look into it :)

@mahabaleshwars mahabaleshwars self-assigned this Apr 10, 2024
@mahabaleshwars
Copy link
Contributor

Hello @LorenzoBettini, I have tried reproducing the issue but I am unable to. I have attached screenshots of the workflow where I am able to use toolchains.xml as expected.

Screenshot 2024-04-15 at 12 11 07 Screenshot 2024-04-15 at 12 30 08

Please consider sharing a public repository for us to examine the workflow and pom.xml file, or provide the steps to reproduce the issue. Thank you.

@LorenzoBettini
Copy link
Contributor Author

@mahabaleshwars thank you for the verification.
Maybe my problem was due to an interaction between Maven and Tycho (the Maven plugin for building Eclipse plugins).
In that case, I could only make it work by creating a toolchains.xml and passing it with the Maven command line option.

@LorenzoBettini
Copy link
Contributor Author

@mahabaleshwars could you please share the project you have used?

@mahabaleshwars
Copy link
Contributor

Hello @LorenzoBettini,I'm pleased to share with you a link to a public repository. Here, you'll find a successful implementation of the workflow and pom profile that aligns with your project. I believe it could be useful for your reference.

@LorenzoBettini
Copy link
Contributor Author

@mahabaleshwars thank you for sharing this. I'll examine that further.
For the moment, in my case, where as I said we use Maven/Tycho, the only way I could find to make it work is this: eclipse/xtext@8f8b905

That is, copy the toolchains.xml generated by the action into another directory (i.e., the root of the git repository) and refer to that with the --toolchains command line argument. I know it makes no sense, but that's the only way to make it work. Just to be clear --toolchains ~/.m2/toolchains.xml does NOT work either.

@mahabaleshwars
Copy link
Contributor

Hello @LorenzoBettini, could you please verify if the provided repository assisted you in resolving the issue?

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

3 participants