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

Recipe org.openrewrite.java.dependencies.AddDependency not working... solo or in org.openrewrite.java.testing.junit5.JUnit4to5Migration #506

Closed
taijidude opened this issue Apr 15, 2024 · 9 comments
Labels
bug Something isn't working question Further information is requested

Comments

@taijidude
Copy link

Hello,

i'm trying to run the following recipe: https://docs.openrewrite.org/recipes/java/testing/junit5/junit4to5migration

but it doesn't adds the junit 5 dependencies. And i'm struggling to figure out why not.

Even my small test is not working:

My pom.xml looks like this:

... more maven stuff ...

       <dependency>
	   <groupId>junit</groupId>
	   <artifactId>junit</artifactId>
	   <version>4.13.2</version>
	   <scope>test</scope>
        </dependency>
</dependencies>	
	
<build>
	<plugins>
		<plugin>
			<groupId>org.openrewrite.maven</groupId>
			<artifactId>rewrite-maven-plugin</artifactId>
			<version>5.28.0</version>
			<dependencies>
				<dependency>
					<groupId>org.openrewrite.recipe</groupId>
					<artifactId>rewrite-migrate-java</artifactId>
					<version>2.11.0</version>
				</dependency>
				<dependency>
					<groupId>org.openrewrite.recipe</groupId>
						<artifactId>rewrite-testing-frameworks</artifactId>
						<version>2.6.0</version>
				</dependency>
			</dependencies>
		</plugin>
	</plugins>
	 </build>

My rewrite.yml looks like this:

type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.junit5.JUnit4to5Migration1
tags:
  - junit
  - testing
recipeList:
  - org.openrewrite.java.dependencies.AddDependency:
      groupId: org.junit.jupiter
      artifactId: junit-jupiter-params
      version: 5.x
      acceptTransitive: true

And my shell command looks like this:

mvn rewrite:run -Drewrite.activeRecipes="org.openrewrite.java.testing.junit5.JUnit4to5Migration1" -Drewrite.configLocation="/c/Dev/test/rewrite.yml"

After this i would expect the new dependency in the pom. But nothing shows up. The output from the maven plugin shows nothing as well.

[INFO] Scanning for projects...
[INFO]
[INFO] -------------< orw:test >--------------
[INFO] Building test - Impl 11.9-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ ejb ]---------------------------------
[INFO]
[INFO] >>> rewrite:5.28.0:run (default-cli) > process-test-classes @ test >>>
[INFO]
[INFO] --- java-formatter:1.0.0:install-git-hook (install-git-hook) @ test ---
[INFO]
[INFO] --- resources:3.3.0:resources (default-resources) @ test ---
[INFO] Copying 20 resources
[INFO]
[INFO] --- compiler:3.10.1:compile (default-compile) @ test ---
[WARNING]  Parameter 'compilerArguments' is deprecated: use {@link #compilerArgs} instead.
[WARNING]  Parameter 'optimize' (user property 'maven.compiler.optimize') is deprecated: This property is a no-op in {@code javac}.
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- build-helper:3.3.0:add-test-source (add-test-source) @ test ---
[INFO] Test Source directory: C:\Dev\gitrepo\test\src\integration-test\java added.
[INFO]
[INFO] --- resources:3.3.0:testResources (default-testResources) @ test ---
[INFO] Copying 0 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- compiler:3.10.1:testCompile (default-testCompile) @ test ---
[WARNING]  Parameter 'compilerArguments' is deprecated: use {@link #compilerArgs} instead.
[WARNING]  Parameter 'optimize' (user property 'maven.compiler.optimize') is deprecated: This property is a no-op in {@code javac}.
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< rewrite:5.28.0:run (default-cli) < process-test-classes @ test <<<
[INFO]
[INFO]
[INFO] --- rewrite:5.28.0:run (default-cli) @ test ---
[INFO] Using active recipe(s) [org.openrewrite.java.testing.junit5.JUnit4to5Migration1]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] Project [Billing Services - Impl] Resolving Poms...
[INFO] Project [Billing Services - Impl] Parsing source files
[INFO] Running recipe(s)...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  50.773 s
[INFO] Finished at: 2024-04-15T17:18:34+02:00
[INFO] ------------------------------------------------------------------------

What am i doing wrong? Or are my assumptions wrong?

@taijidude taijidude added the bug Something isn't working label Apr 15, 2024
@timtebeek timtebeek added the question Further information is requested label Apr 15, 2024
@timtebeek
Copy link
Contributor

Why are you running it like that? You should not have to define any AddDependency recipe or rewrite.yml file yourself.

Does your project get updated correctly when you

  1. remove the plugin from your pom.xml
  2. remove rewrite.yml
  3. run the following command
    mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.testing.junit5.JUnit4to5Migration
    
    ?

@taijidude
Copy link
Author

Thanks for the reply. Tried your command and it doesn't work for. The pom doesn't change. No Junit Jupiter Dependency added.

@timtebeek
Copy link
Contributor

And to be sure: you don't already have a transitive dependency on JUnit Jupiter? Does your project not compile after the code changes are made?

It's been a couple weeks since we last released; I think there were some small fixes around adding dependencies that still need to go out in a new release. You could try our snapshot versions to see if that might help; otherwise it'll be a couple days until the next release.

@taijidude
Copy link
Author

taijidude commented Apr 16, 2024

  • I checked the transitiv dependencies with mvn dependency:tree. Just found the junit4 dependencies.
  • Yes, when i run your command from above i get compile errors. For junit annotations. With my main project the output says, that the only recipe, that has been run is: org.openrewrite.java.testing.junit5.UpdateTestAnnotation

Thanks for your help and the hint about the snapshot version. Will try this.

@taijidude
Copy link
Author

taijidude commented Apr 16, 2024

Update: I generated a maven project with maven java quickstart archetype and then run the mvn command from above to migrate from junit4 to junit5.

Works fine. So, there is some problem with the project i'm trying to migrate. While in my main project only the UpdateTestAnnotation Recipe is executed. The output in my toy project looks like this:

[WARNING] Changes have been made to pom.xml by:
[WARNING]     org.openrewrite.java.testing.junit5.JUnit4to5Migration
[WARNING]         org.openrewrite.java.dependencies.RemoveDependency: {groupId=junit, artifactId=junit}
[WARNING]             org.openrewrite.maven.RemoveDependency: {groupId=junit, artifactId=junit}
[WARNING]         org.openrewrite.java.dependencies.AddDependency: {groupId=org.junit.jupiter, artifactId=junit-jupiter, version=5.x, onlyIfUsing=org.junit..*, scope=test}
[WARNING] Changes have been made to src\test\java\com\rtl\tech\AppTest.java by:
[WARNING]     org.openrewrite.java.testing.junit5.JUnit4to5Migration
[WARNING]         org.openrewrite.java.testing.junit5.AssertToAssertions
[WARNING]         org.openrewrite.java.testing.junit5.UpdateTestAnnotation
[WARNING] Please review and commit the results.

@taijidude
Copy link
Author

Update i ran the shell following shell command and stumbled over an exception i didn't notice before:

mvn org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.testing.junit5.JUnit4to5Migration -X

The exception:

org.openrewrite.maven.MavenDownloadingExceptions
    at org.openrewrite.maven.MavenDownloadingExceptions.append (MavenDownloadingExceptions.java:44)
    at org.openrewrite.maven.tree.MavenResolutionResult.resolveDependencies (MavenResolutionResult.java:179)
    at org.openrewrite.maven.MavenParser.parseInputs (MavenParser.java:116)
    at org.openrewrite.Parser.parse (Parser.java:59)
    at org.openrewrite.maven.MavenMojoProjectParser.parseMaven (MavenMojoProjectParser.java:557)
    at org.openrewrite.maven.MavenMojoProjectParser.listSourceFiles (MavenMojoProjectParser.java:149)
    at org.openrewrite.maven.AbstractRewriteMojo.loadSourceSet (AbstractRewriteMojo.java:258)
    at org.openrewrite.maven.AbstractRewriteMojo.listResults (AbstractRewriteMojo.java:240)
    at org.openrewrite.maven.AbstractRewriteRunMojo.execute (AbstractRewriteRunMojo.java:62)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
    Suppressed: org.openrewrite.maven.MavenDownloadingException: org.hamcrest:hamcrest failed. No version provided
        at org.openrewrite.maven.tree.ResolvedPom.resolveDependencies (ResolvedPom.java:784)
        at org.openrewrite.maven.tree.ResolvedPom.resolveDependencies (ResolvedPom.java:756)
        at org.openrewrite.maven.tree.MavenResolutionResult.resolveDependencies (MavenResolutionResult.java:174)
        at org.openrewrite.maven.MavenParser.parseInputs (MavenParser.java:116)
        at org.openrewrite.Parser.parse (Parser.java:59)
        at org.openrewrite.maven.MavenMojoProjectParser.parseMaven (MavenMojoProjectParser.java:557)
        at org.openrewrite.maven.MavenMojoProjectParser.listSourceFiles (MavenMojoProjectParser.java:149)
        at org.openrewrite.maven.AbstractRewriteMojo.loadSourceSet (AbstractRewriteMojo.java:258)
        at org.openrewrite.maven.AbstractRewriteMojo.listResults (AbstractRewriteMojo.java:240)
        at org.openrewrite.maven.AbstractRewriteRunMojo.execute (AbstractRewriteRunMojo.java:62)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
        at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
        at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
        at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
        at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
        at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
        at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
        at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
        at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
        at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke (Method.java:568)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)

We don't have any dependency like this in our project.

I will keep digging and keep you posted.

@timtebeek
Copy link
Contributor

I only just now noticed you're using build-helper-maven-plugin to add a test source dependency at C:\Dev\gitrepo\test\src\integration-test\java. This is something we don't yet support, as the Maven plugin on parses src/main and src/test. Perhaps that factors in here? Do you also have a regular src/test folder as well?

@taijidude
Copy link
Author

Thanks, will check it out in monday. Was on the backburner for a while.

@timtebeek
Copy link
Contributor

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
Archived in project
Development

No branches or pull requests

2 participants