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

migrator does not honor Maven settings.xml #573

Closed
eidottermihi opened this issue Nov 27, 2022 · 7 comments · Fixed by #581
Closed

migrator does not honor Maven settings.xml #573

eidottermihi opened this issue Nov 27, 2022 · 7 comments · Fixed by #581
Assignees
Labels
type: bug Something isn't working
Milestone

Comments

@eidottermihi
Copy link

Describe the bug

When scanning an application in a corporate environment including internet proxy and internal Maven Repository mirrors definend in a Maven setttings.xml, the scan step fails:

migrator:> scan ./myrepo

scanning './myrepo'

Checked preconditions for 'C:\Users\michael.prankl\git\myrepo'
[ok] Found pom.xml.
[ok] 'sbm.gitSupportEnabled' is 'true', changes will be committed to branch [spring-boot-3] after each recipe.
[ok] Required Java version (17) was found.
[ok] Found required source dir 'src/main/java'.


Maven         14% ?????                       ? 1/7 (0:00:00 / 0:00:00) Unable to download dependency org.springframework.boot:spring-boot-starter-parent:2.7.6 from the following repositories :
  - file:/C:/Users/michael.prankl/.m2/repository/
  - https://repo.maven.apache.org/maven2
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.

To Reproduce
Steps to reproduce the behavior:

  1. Define a settings.xml containing proxy or mirror:
<settings
    xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

	<proxies>
		<proxy>
			<id>my-proxy</id>
			<active>true</active>
			<protocol>http</protocol>
			<host>my-corporate-proxy-host</host>
			<port>80</port>
		</proxy>
	</proxies>

</settings>
  1. run the scan

Expected behavior

The migrator should honor user specific maven settings defined in ~/.m2/settings.xml, and therefore Maven should use the defined proxy for downlodas.

Screenshots

n/a

Stacktrace

org.openrewrite.maven.internal.MavenDownloadingException: Unable to download dependency org.springframework.boot:spring-boot-starter-parent:2.7.6 from the following repositories :
  - file:/C:/Users/michael.prankl/.m2/repository/
  - https://repo.maven.apache.org/maven2
        at org.openrewrite.maven.internal.MavenPomDownloader.download(MavenPomDownloader.java:311)
        at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentPropertiesAndRepositoriesRecursively(ResolvedPom.java:351)
        at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentPropertiesAndRepositoriesRecursively(ResolvedPom.java:362)
        at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentsRecursively(ResolvedPom.java:308)
        at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolve(ResolvedPom.java:297)
        at org.openrewrite.maven.tree.ResolvedPom.resolve(ResolvedPom.java:142)
        at org.openrewrite.maven.tree.Pom.resolve(Pom.java:92)
        at org.openrewrite.maven.MavenParser.parseInputs(MavenParser.java:113)
        at org.springframework.sbm.build.impl.RewriteMavenParser.parseInputs(RewriteMavenParser.java:71)
        at org.springframework.sbm.project.parser.MavenProjectParser.parse(MavenProjectParser.java:102)
        at org.springframework.sbm.project.parser.ProjectContextInitializer.initProjectContext(ProjectContextInitializer.java:54)
        at org.springframework.sbm.engine.commands.ScanCommand.execute(ScanCommand.java:57)
        at org.springframework.sbm.shell.ScanShellCommand.scan(ScanShellCommand.java:70)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.springframework.shell.command.invocation.InvocableShellMethod.doInvoke(InvocableShellMethod.java:306)
        at org.springframework.shell.command.invocation.InvocableShellMethod.invoke(InvocableShellMethod.java:232)
        at org.springframework.shell.command.CommandExecution$DefaultCommandExecution.evaluate(CommandExecution.java:158)
        at org.springframework.shell.Shell.evaluate(Shell.java:208)
        at org.springframework.shell.Shell.run(Shell.java:140)
        at org.springframework.shell.jline.InteractiveShellRunner.run(InteractiveShellRunner.java:73)
        at org.springframework.shell.DefaultShellApplicationRunner.run(DefaultShellApplicationRunner.java:65)
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762)
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
        at org.springframework.sbm.SpringShellApplication.main(SpringShellApplication.java:27)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)

Desktop (please complete the following information):

  • OS: Windows
  • Version: 21H2
@fabapp2
Copy link
Collaborator

fabapp2 commented Nov 29, 2022

HI @eidottermihi

thanks for reporting! 🚀
I am aware but will provide a fix for this (today 🤞).

@fabapp2 fabapp2 added the type: bug Something isn't working label Nov 29, 2022
@fabapp2 fabapp2 added this to To do in Spring Boot core via automation Nov 29, 2022
@fabapp2 fabapp2 added this to the v0.13.0 milestone Nov 29, 2022
@fabapp2 fabapp2 self-assigned this Nov 29, 2022
@fabapp2 fabapp2 linked a pull request Nov 29, 2022 that will close this issue
@fabapp2
Copy link
Collaborator

fabapp2 commented Nov 29, 2022

Hi @eidottermihi
the proxy settings are not yet read by OpenRewrite, I talked to them and they'll look into it.
If possible for you, could you maybe try to use mirror settings and see if this works for you after #581 was merged?

@sleicht
Copy link

sleicht commented Nov 30, 2022

Hi @fabapp2
I tried to start the migrator with your changes. It fails to start because RewriteMavenParser doesn't have a default constructor and cannot be autowired. Any particular reason why MavenSettingsInitializer is not instantiated by the class itself? This way the app is starting:

    private final MavenSettingsInitializer mavenSettingsInitializer = new MavenSettingsInitializer();

    public RewriteMavenParser( Path projectRoot) {
        parser = initMavenParser(new RewriteExecutionContext(), Optional.ofNullable(projectRoot));
    }

    public RewriteMavenParser() {
        parser = initMavenParser(new RewriteExecutionContext(), Optional.empty());
    }

Spring Boot core automation moved this from To do to Done Nov 30, 2022
@fabapp2
Copy link
Collaborator

fabapp2 commented Nov 30, 2022

Hi @sleicht sorry for pointing you to an erroneous app.
The motivation to introduce MavenSettingsInitializer was simpler testing (and arguably separation of concern).
But to make testing simpler it needs to be replaceable, thus the constructor injection.
I removed the RewriteMavenParser constructor taking a Path which was not a good idea in the first place and was also preventing DI and leading to the error you mentioned.
It's merged and should work now.

@sleicht
Copy link

sleicht commented Dec 1, 2022

No worries @fabapp2
Thank you for fixing this issue and maintaining this project.

@Avagenzo
Copy link

Avagenzo commented Oct 2, 2023

I also have a user defined settings.xml in my Users folder (Windows), where im pointing to a gitlab server. This takes me to a UnknwonHostException:

Checked preconditions for '/mnt/c/projects/project-mock'
[ok] Found pom.xml.
[ok] 'sbm.gitSupportEnabled' is 'true', changes will be committed to branch [migrator] after each recipe.
[ok] Required Java version (17) was found.
[ok] Found required source dir 'src/main/java'.


Maven        100% │██████████████████████████████████│ 2/2 (0:00:02 / 0:00:00) Failed to download dependencies for pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>example.demo</groupId>
    <artifactId>project-mock</artifactId>
    <version>2.0.1</version>

    <!--~~(example.demo:project-bom:0.8.0 failed. Unable to download POM. Tried repositories:
https://repo.maven.apache.org/maven2: java.net.UnknownHostException: repo.maven.apache.org)~~>--><parent>
        <groupId>example.demo</groupId>
        <artifactId>project-bom</artifactId>
        <version>0.8.0</version>
    </parent>

How can i resolve this issue?

@fabapp2
Copy link
Collaborator

fabapp2 commented Oct 20, 2023

Hi, @Avagenzo the current releases as well as code in main branch don't support Maven setttings.xml.
This is the issue for the support in the version/revamp branch.

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

Successfully merging a pull request may close this issue.

4 participants