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

Cannot update internal parent resolvable through company mirror #4589

Open
natalia-pokrovskaya opened this issue Oct 18, 2024 · 7 comments
Open
Labels
bug Something isn't working question Further information is requested

Comments

@natalia-pokrovskaya
Copy link

Hello,

I have an issue running custom recipie for org.openrewrite.maven.ChangeParentPom

Here is my configuration:
A maven, multi-module project. I want to update the version of the parent of the root's pom.xml file.

Here is my configuration in rules.yml file:

type: specs.openrewrite.org/v1beta/recipe
name: my.test.UpgradeParent
displayName: Change Maven dependency example
recipeList:
  - org.openrewrite.maven.ChangeParentPom:
      oldGroupId: com.my.group
      oldArtifactId: my-artifact
      newVersion: 1.0.4

In my pom.xml I have:

<project>
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.my.group</groupId>
        <artifactId>my-artifact</artifactId>
        <version>1.107</version>
    </parent>

    <build>
        <plugins>
            <plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>5.42.2</version>
                <configuration>
                    <configLocation>rules.yml</configLocation>
                    <activeRecipes>
                        <recipe>my.test.UpgradeParent</recipe>
                    </activeRecipes>
                    <failOnInvalidActiveRecipes>true</failOnInvalidActiveRecipes>
                </configuration>
            </plugin>
        </plugins>
    </build>
...

But when I run it with rewrite:run or rewrite:dryRun, it doesn't match my parent pom GAV and don't update it...

[INFO] --- rewrite:5.42.2:dryRun (default-cli) @ XXXXX-module ---
[INFO] Using active recipe(s) [com.bnppf.UpgradeToSf5]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] Project [XXXXX] Resolving Poms...
[INFO] Project [XXXXX] Parsing source files
[INFO] Project [XXXXX-module1] Parsing source files
[INFO] Project [XXXXX-module2] Parsing source files
[INFO] Project [XXXXX-module3] Parsing source files
[INFO] Project [XXXXX-module4] Parsing source files
[INFO] Project [XXXXX-module5] Parsing source files
[INFO] Running recipe(s)...
[INFO] Applying recipes would make no changes. No patch file generated.

I tried to specify newArtifactId, newGroupId, but it changes nothing.... What am I doing wrong?
Any help will be highly appreciated...

Thank you very much in advance!

I am using:

  • Maven plugin v5.42.2
  • Java version: 1.8 (and 11 and 17)
  • Maven version: 3.9.9
@natalia-pokrovskaya natalia-pokrovskaya added the bug Something isn't working label Oct 18, 2024
@timtebeek
Copy link
Contributor

Hi @natalia-pokrovskaya ; thanks for the detailed report. Since it looks to be an internal parent that can not be upgraded I'm wondering if your repositories are configured correctly. Does it work when you try to change the parent pom from one that's available in Maven Central?

@timtebeek timtebeek added the question Further information is requested label Oct 20, 2024
@svaningelgem
Copy link

svaningelgem commented Oct 21, 2024

I created a very simple project (don't blame me, blame the chatbot for the bad code :p):

structure:

my-parent-project/
├── pom.xml
├── my-module/
│   └── pom.xml
_pom.xml:_

```xml 4.0.0

<parent>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-parent</artifactId>
    <version>33</version>
</parent>

<groupId>com.example</groupId>
<artifactId>my-parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>My Parent Project</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<modules>
    <module>my-module</module>
</modules>

<build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
        <plugins>
            <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
            <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.2.0</version>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
            </plugin>
            <plugin>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>
            <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
            <plugin>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.7.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
```

_my-module/pom.xml:_

```xml 4.0.0

<parent>
    <groupId>com.example</groupId>
    <artifactId>my-parent-project</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>

<groupId>com.example</groupId>
<artifactId>my-module</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>My Module</name>
<url>http://maven.apache.org</url>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>
```

Step 1: see that it compiles (✅)
Step 2: add rewrite to it:

_Adjusted pom.xml:_

(See bottom for build plugin -- literally taken from @natalia-pokrovskaya 's example above)

<!--
  ~ Copyright [Year] [Your Name]
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
-->
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-parent</artifactId>
        <version>33</version>
    </parent>

    <groupId>com.example</groupId>
    <artifactId>my-parent-project</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>My Parent Project</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <modules>
        <module>my-module</module>
    </modules>

    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.2.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.2.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.7.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                <plugin>
                    <groupId>org.openrewrite.maven</groupId>
                    <artifactId>rewrite-maven-plugin</artifactId>
                    <version>5.42.2</version>
                    <configuration>
                        <configLocation>rules.yml</configLocation>
                        <activeRecipes>
                            <recipe>my.test.UpgradeParent</recipe>
                        </activeRecipes>
                        <failOnInvalidActiveRecipes>true</failOnInvalidActiveRecipes>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

Step 2b: Add my-module/rules.yml [strange location -- not the root, but the last project executed!!!!]:

_rules.yml:_

```yaml type: specs.openrewrite.org/v1beta/recipe name: my.test.UpgradeParent displayName: Change Maven dependency example recipeList: - org.openrewrite.maven.ChangeParentPom: oldGroupId: org.apache.maven oldArtifactId: maven-parent newVersion: 34 ```

Step 3: run it (mvn rewrite:run -Drat.skip=true)
Step 4: works! ‼
Result:

[INFO] --- rewrite:5.42.2:run (default-cli) @ my-module ---
[INFO] Using active recipe(s) [my.test.UpgradeParent]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] Project [My Parent Project] Resolving Poms...
[INFO] Project [My Parent Project] Parsing source files
[INFO] Project [My Module] Parsing source files
[INFO] Running recipe(s)...
[WARNING] Changes have been made to pom.xml by:
[WARNING]     org.openrewrite.maven.ChangeParentPom: {oldGroupId=org.apache.maven, oldArtifactId=maven-parent, newVersion=34}
[WARNING] Please review and commit the results.

But that would mean that the openrewrite plugin is not very useful for any project which is not on the central maven repository?
Even though we have a Nexus repository where all the calls are redirected to, openrewrite still tries somehow to go to central as I understand it?

I verified that it doesn't work against an internal parent pom.

@timtebeek
Copy link
Contributor

hi @svaningelgem ; thanks for reporducing. I imagine you're a colleague of @natalia-pokrovskaya and as such are using much of the same settings? OpenRewrite definitely does work for internal projects as well, but perhaps there's an issue with the specific configuration that you're using. Whenever possible we try to use <repositories> and ~/.m2/settings.xml to discover which internal repositories to reach out to, and what credentials to use for those. Sometimes we find those might need to be tweaked or made a little more explicit when there's internal alternative authentication schemes for instance. Are you using any Artifactory that allows you to download & provide a custom settings.xml for instance?

@svaningelgem
Copy link

svaningelgem commented Oct 21, 2024

You've guessed correct @timtebeek 👍 .

I have an ~/.m2/settings.xml in which I have 1 repository set, with mirrorOf set to *.
Authentication scheme is via username/password, also defined in this settings file.

So, nothing out of the ordinary there (I think)...

@natalia-pokrovskaya
Copy link
Author

hi @timtebeek, thank you very much for the reply! yes, we are using our internal next to proxy everything.

in my settings.xml I have:

   <mirrors>
        <mirror>
            <id>Maven_Public</id>
            <mirrorOf>*</mirrorOf>     
            <url>****https://nexus_URL***/</url>
        </mirror>
    </mirrors>

 
	<profiles>
		<profile>
			<id>global</id>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
			<repositories>
				<repository>
					<id>Maven_Public</id>
					<name>Nexus Public Repository</name>
					<url>https://***nexus_URL***</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
						<updatePolicy>always</updatePolicy>
					</snapshots>
				</repository>				
			</repositories>
		</profile>
	</profiles>

but when checking for logs, I have no impression openrewrite check our custom repositories....
should we add something on the project level?
How I can debug it deeply?

Thank you in advance for your help!

best regards,
Natalia

@svaningelgem
Copy link

In my settings file I simply have this:

<settings>
	<servers>
		<server>
	    	<id>Maven_Public</id>
	    	<username>%my username%</username>
	    	<password>%pass%</password>   
	    </server>
	</servers>

	<mirrors>
		<mirror>
			<id>Maven_Public</id>
			<mirrorOf>*</mirrorOf>     
			<url>%our nexus url%</url>
		</mirror>
	</mirrors>
</settings>

So, a lot less than @natalia-pokrovskaya . But indeed, it looks to be bypassing our local nexus server in favor of an external one?

@stevenniu9527
Copy link

I have same issue,when ChangeParentPom with local mirror server .

@timtebeek timtebeek changed the title Cannot update parent in pom.xml Cannot update internal parent resolvable through company mirror Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
Status: No status
Development

No branches or pull requests

4 participants