timboudreau opened a new issue, #4576:
URL: https://github.com/apache/netbeans/issues/4576

   ### Apache NetBeans version
   
   Apache NetBeans latest daily build
   
   ### What happened
   
   Create/Update tests should, in maven projects at the least, detect if a 
JUnit (or whatever - TestNG likely has the same problem) dependency *already 
exists in the project*, and either
   
    * Not modify the `pom.xml` at all, or
    * At the very least, not insert a `<version>` tag if the dependency is 
already satisfied
   
   Using locally built nightly build + Maven 3.8.6 in a a large tree of maven 
projects with carefully managed dependencies, all of which are *using the java 
module system*.  The Maven Enforcer Plugin is used to enforce dependency 
convergence - there shall be no more than one exact version of any dependency 
on the classpath.
   
   Every time I use Create/Update tests, a `<version>5.6.0</version>` entry is 
added to the *already existing* `<dependency>` entries for `junit-jupiter-api`, 
`junit-jupiter-params`, and `junit-jupiter-engine`, inherited from the 
`<dependencyManagement>` section of the superpom, with a version of `5.8.2`.  
So, dependencies no longer converge and the next build fails.
   
   The IDE could easily either examine the artifacts in the dependency graph to 
determine that the dependency is not satisfied, or examine the project 
classpath and test for one type known to be in each library, and simply skip 
doing any messing with dependencies - it doesn't need to.
   
   I have not seen this before working in non-modular project, so I am not sure 
if the presence of a module-info somehow makes the fact that the dependencies 
are there opaque to the infrastructure that decides to fiddle with dependencies.
   
   That, and the fact that the superpoms live in a different git repository and 
cannot be referenced by relative path are the two things that are somewhat 
unusual about the projects I have encountered this on.  
   
   So I am not sure if something changed in the plugin and broke former, good 
handling of adding junit dependencies; or if it has always been broken if you 
are using the module system, and I simply never triggered the problem before.
   
   ### How to reproduce
   
   Create a superpom maven project.  To replicate the exact setup in which I am 
encountering this, do **not** have it accessible via `<relativePath>`.  Give 
it, at minimum, properties and a dependency management section like this:
   
   ```xml
       <properties><junit5.version>5.8.2</junit5.version></properties>
       <dependencyManagement>
               <dependency>
                   <groupId>org.junit.jupiter</groupId>
                   <artifactId>junit-jupiter</artifactId>
                   <version>${junit5.version}</version>
               </dependency>
               <dependency>
                   <groupId>org.junit.jupiter</groupId>
                   <artifactId>junit-jupiter-api</artifactId>
                   <version>${junit5.version}</version>
               </dependency>
               <dependency>
                   <groupId>org.junit.jupiter</groupId>
                   <artifactId>junit-jupiter-engine</artifactId>
                   <version>${junit5.version}</version>
               </dependency>
               <dependency>
                   <groupId>org.junit.jupiter</groupId>
                   <artifactId>junit-jupiter-migrationsupport</artifactId>
                   <version>${junit5.version}</version>
               </dependency>
               <dependency>
                   <groupId>org.junit.jupiter</groupId>
                   <artifactId>junit-jupiter-params</artifactId>
                   <version>${junit5.version}</version>
               </dependency>
       <dependencyManagement>
       <build>
           <plugins>
               <plugin>
   
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-enforcer-plugin</artifactId>
                   <version>3.0.0</version>
                   <executions>
                       <execution>
                           <id>enforce</id>
                           <configuration>
                               <rules>
                                   <dependencyConvergence/>
                                   <requireMavenVersion>
                                       <version>3.8.6</version>
                                       <message>
                                           Build requires Maven version 3.8.6.
                                       </message>
                                   </requireMavenVersion>
                               </rules>
                           </configuration>
                           <goals>
                               <goal>enforce</goal>
                           </goals>
                       </execution>
                   </executions>
               </plugin>
           </plugins>
       </build>
   ```
   
   In the project you will create tests in, create some class to test, and give 
the project a `module-info.java` in the default package.  Set up the parent in 
its pom to be your superpom project - e.g.
   
   ```xml
       <parent>
           <groupId>test.mytestorg</groupId>
           <artifactId>my-test-superpom</artifactId>
           <version>0.0.1</version>
           <relativePath/>
       </parent>
   ```
   
   and give it dependencies on junit 5 *without specifying the version* (since 
that is inherited and should only be specified in one place):
   
   ```
           <dependency>
               <groupId>org.junit.jupiter</groupId>
               <artifactId>junit-jupiter-api</artifactId>
               <scope>test</scope>
           </dependency>
           <dependency>
               <groupId>org.junit.jupiter</groupId>
               <artifactId>junit-jupiter-params</artifactId>
               <scope>test</scope>
           </dependency>
           <dependency>
               <groupId>org.junit.jupiter</groupId>
               <artifactId>junit-jupiter-engine</artifactId>
               <scope>test</scope>
           </dependency>
   ```
   
   Each time you add a test, a (wrong) `<version> entry will be added to each 
dependency, which you have to go delete.
   
   ### Did this work correctly in an earlier version?
   
   No / Don't know
   
   ### Operating System
   
   Mac OS X 21.4.0, Apple Silicon 10 Core MacBook Pro
   
   ### JDK
   
   Amazon Corretto 17
   
   ### Apache NetBeans packaging
   
   Own source build
   
   ### Anything else
   
   Every time I use Tools > Create/Update Tests on the popup menu for a Java 
source to create a new test in a project with existing tests and existing JUnit 
dependencies.
   
   ### Are you willing to submit a pull request?
   
   No
   
   ### Code of Conduct
   
   Yes


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to