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

Reading maven settings is not working with Jackson 2.18 in the classpath #4803

Open
ammachado opened this issue Dec 19, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@ammachado
Copy link
Contributor

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v8.42.0
  • Maven/Gradle plugin v5.47.0
  • rewrite-java-17 v8.42.0

How are you running OpenRewrite?

I am using the Maven plugin via CLI, and my project is a single module project.

What is the smallest, simplest way to reproduce the problem?

I have a custom set of recipes. When Jackson 2.18.2 is present on the classpath, I get the following error while running the existing recipe tests:

java.lang.AssertionError: Failed to parse sources or run recipe
        at org.openrewrite.test.RewriteTest.lambda$defaultExecutionContext$14(RewriteTest.java:636)
        at org.openrewrite.maven.MavenSettings.parse(MavenSettings.java:104)
        at org.openrewrite.maven.MavenSettings.parse(MavenSettings.java:110)
        at org.openrewrite.maven.MavenSettings.lambda$readMavenSettingsFromDisk$1(MavenSettings.java:123)
        at java.base/java.util.Optional.map(Optional.java:260)
        at org.openrewrite.maven.MavenSettings.readMavenSettingsFromDisk(MavenSettings.java:123)
        at org.openrewrite.maven.Assertions.customizeExecutionContext(Assertions.java:41)
        at org.openrewrite.internal.ThrowingConsumer.accept(ThrowingConsumer.java:26)
        at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:217)
        at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:132)
        at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:127)
        at com.redhat.recipe.maven.ChangePropertiesTest.testPomPropertiesTest(ChangePropertiesTest.java:20)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.io.IOException: Failed to parse C:\Users\ammachado\.m2\settings.xml
        ... 14 more
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Invalid definition for property 'httpHeaders' (of type `org.openrewrite.maven.MavenSettings$ServerConfiguration`): Could not find creator property with name 'httpHeaders' (known Creator properties: [property, timeout])
 at [Source: (org.openrewrite.internal.EncodingDetectingInputStream); line: 2, column: 1]

The maven settings.xml file is the following:

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <mirrors>
    <mirror>
      <mirrorOf>*,!maven-snapshot-repos</mirrorOf>
      <id>maven-release-repos</id>
      <name>maven-release-repos</name>
      <url>https://repo.example.com/artifactory/maven-release-repos/</url>
    </mirror>
  </mirrors>
  <pluginGroups>
    <pluginGroup>org.openrewrite.maven</pluginGroup>
  </pluginGroups>
  <profiles>
    <profile>
      <id>artifactory</id>
      <repositories>
        <repository>
          <id>maven-release-repos</id>
          <name>maven-release-repos</name>
          <url>https://repo.example.com/artifactory/maven-release-repos/</url>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>maven-snapshot-repos</id>
          <name>maven-snapshot-repos</name>
          <url>https://repo.example.com/artifactory/maven-snapshot-repos/</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>
</settings>

What did you expect to see?

No execution errors.

What did you see instead?

The beforementioned exception.

What is the full stack trace of any errors you encountered?

java.lang.AssertionError: Failed to parse sources or run recipe
        at org.openrewrite.test.RewriteTest.lambda$defaultExecutionContext$14(RewriteTest.java:636)
        at org.openrewrite.maven.MavenSettings.parse(MavenSettings.java:104)
        at org.openrewrite.maven.MavenSettings.parse(MavenSettings.java:110)
        at org.openrewrite.maven.MavenSettings.lambda$readMavenSettingsFromDisk$1(MavenSettings.java:123)
        at java.base/java.util.Optional.map(Optional.java:260)
        at org.openrewrite.maven.MavenSettings.readMavenSettingsFromDisk(MavenSettings.java:123)
        at org.openrewrite.maven.Assertions.customizeExecutionContext(Assertions.java:41)
        at org.openrewrite.internal.ThrowingConsumer.accept(ThrowingConsumer.java:26)
        at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:217)
        at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:132)
        at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:127)
        at com.redhat.recipe.maven.RemoveEarProjectsTest.test(RemoveEarProjectsTest.java:113)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.io.IOException: Failed to parse C:\Users\ammachado\.m2\settings.xml
        ... 14 more
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Invalid definition for property 'httpHeaders' (of type `org.openrewrite.maven.MavenSettings$ServerConfiguration`): Could not find creator property with name 'httpHeaders' (known Creator properties: [property, timeout])
 at [Source: (org.openrewrite.internal.EncodingDetectingInputStream); line: 2, column: 1]
        at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:62)
        at com.fasterxml.jackson.databind.DeserializationContext.reportBadPropertyDefinition(DeserializationContext.java:1883)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:636)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:277)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:151)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:471)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:415)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:317)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:284)
        at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:174)
        at com.fasterxml.jackson.databind.DeserializationContext.findNonContextualValueDeserializer(DeserializationContext.java:659)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:552)
        at com.fasterxml.jackson.databind.deser.std.DelegatingDeserializer.resolve(DelegatingDeserializer.java:60)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:347)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:284)
        at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:174)
        at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:636)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:190)
        at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.createContextual(CollectionDeserializer.java:30)
        at com.fasterxml.jackson.databind.DeserializationContext.handlePrimaryContextualization(DeserializationContext.java:851)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:563)
        at com.fasterxml.jackson.databind.deser.std.DelegatingDeserializer.resolve(DelegatingDeserializer.java:60)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:347)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:284)
        at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:174)
        at com.fasterxml.jackson.databind.DeserializationContext.findNonContextualValueDeserializer(DeserializationContext.java:659)
        at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:552)
        at com.fasterxml.jackson.databind.deser.std.DelegatingDeserializer.resolve(DelegatingDeserializer.java:60)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:347)
        at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:284)
        at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:174)
        at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:669)
        at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:5048)
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4918)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3897)
        at org.openrewrite.maven.MavenSettings.parse(MavenSettings.java:102)

Are you interested in [contributing a fix to OpenRewrite]

Yes

@ammachado ammachado added the bug Something isn't working label Dec 19, 2024
@timtebeek
Copy link
Contributor

Thanks for looking into it!

@ammachado
Copy link
Contributor Author

How do I override the version? Do I have to publish a new version of the build plugins?

@timtebeek
Copy link
Contributor

Good question! I've never looked into that part before; I do indeed see a reference here in the build plugin that you likely also saw:
https://github.com/openrewrite/rewrite-build-gradle-plugin/blob/a6a7fd4ef41b0e123df09bc036a20c697b8cc485/src/main/java/org/openrewrite/gradle/RewriteJavaPlugin.java#L78
https://github.com/openrewrite/rewrite-build-gradle-plugin/blob/a6a7fd4ef41b0e123df09bc036a20c697b8cc485/src/main/java/org/openrewrite/gradle/RewriteJavaPlugin.java#L39-L40

Overriding that and installing it locally seems like the way to go.

Once we're closer to a fix I wonder if it makes sense to just bump the version to 2.18.+ going forward. Any thoughts to that?

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
Status: No status
Development

No branches or pull requests

2 participants