Is there a way I can have the aspectj maven plugin ignore missing weave dependencies instead of failing the build?

I wrote an aspect library that auto-instruments traces and because most of the developers using this have multi-module projects, it would be nice if they could just configure the aspectj-maven-plugin for compile-time weaving in the parent pom.xml instead of each module’s pom.xml. The problem is that not all modules require certain weave dependencies and as such I would like it if the plugin could ignore those missing dependencies when weaving those modules instead of failing the build. Is this even possible?

ssl – we are performing mysql crawling on 4 different client environments which has centos7 by upgrading maven dependecy jar version from 5.1.6 to 8.0.2

we are performing crawling on our four different client environments by upgrading maven dependecy jar version from 5.1.6 to 8.0.2.

As per below mysql link connection should be established to mysql server from client environment using ssl(i.e through SSL Handshake.)after upgrading to maven dependency jar version 8.0.2.

https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-using-ssl.html

it is performing ssl handshake by using code itself for connecting to mysql server from 3 environments as expected and as per given in documentation.

But in one environment after upgrading to maven dependency jar version 8.0.2. it is not using ssl handshake to connect to mysql server rather it is connecting through jdbc url with username and password to connect to mysql server which was the case in previous version of maven dependency jar version 5.1.6.


mysql
mysql-connector-java
8.0.12

Steps Taken to trouble shoot the issue- we have downgraded the maven dependency jar version from 8.0.2 to5.1.6 and upgraded again to 8.0.2.
still it is asking for username and pass which is the case of lower maven dependency jar version 5.1.6.

Would any of you please guide us how to proceed further in order to trouble shoot this issue.

versioning – Maven: Should I increment the version on configuration change for WARs?

In What Semantic Version increment to use for a configuration file alteration? the question arose if the version of the artifact should be incremented when the configuration, which is part and deployed with the artifact, changes.

A rule of thumbs seems to be: Whenever the created artifact changes, increment the version.

But what about Maven projects which create WARs and simultaneously a JAR (i.e. maven-war-plugin with <attachClasses>true</attachClasses>?

The incremented version reflects the changes made in the WAR, which contains the configuration changes, but the resulting JAR stays the same and may confuse other developers depending on the project.

Are there any good practices how to handle these situations?

java – Maven project using EclipseLink for persistence runs on IDE, but fails when running from a built jar

I’m working on a maven project using eclipselink 2.7.8 for persistence. When I run it on my IDE (Netbeans 12.0) it works perfectly well, but when I attempt to run it from a built jar it doesn’t.

This is the stack trace when I use the jar

Exception in thread "main" Local Exception Stack:
Exception (EclipseLink-30005) (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: jdk.internal.loader.ClassLoaders$AppClassLoader@2cdf8d8a
Internal Exception: javax.persistence.PersistenceException: Exception (EclipseLink-28018) (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit (MyPersistenceUnit) failed.
Internal Exception: java.lang.NullPointerException
        at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:129)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:118)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:191)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
        ...
Caused by: javax.persistence.PersistenceException: Exception (EclipseLink-28018) (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit (MyPersistenceUnit) failed.
Internal Exception: java.lang.NullPointerException
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:2109)
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:2085)
        at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:104)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
        ... 15 more
Caused by: Exception (EclipseLink-28018) (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit (MyPersistenceUnit) failed.
Internal Exception: java.lang.NullPointerException
        at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:233)
        ... 19 more
Caused by: java.lang.NullPointerException
        at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.hasEntity(MetadataProject.java:1441)
        at org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAnnotatedElement.isOneToMany(MetadataAnnotatedElement.java:693)
        at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.buildAccessor(ClassAccessor.java:609)
        at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessorFields(ClassAccessor.java:438)
        at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessors(ClassAccessor.java:410)
        at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.preProcess(ClassAccessor.java:1225)
        at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EmbeddableAccessor.preProcess(EmbeddableAccessor.java:304)
        at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage1(MetadataProject.java:1851)
        at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:579)
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:629)
        at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:2006)
        ... 17 more

My persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
      <persistence-unit name="MyPersistenceUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        ...
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:h2:./bd/MyPersistenceUnit"/>
            <property name="javax.persistence.jdbc.user" value=""/>
            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
            <property name="javax.persistence.jdbc.password" value=""/>
            <property name="javax.persistence.schema-generation.database.action" value="create"/>
        </properties>
    </persistence-unit>
</persistence>

My pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <groupId>xxxx.xxxxx</groupId>
    <artifactId>Service</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    
    <properties>      
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.7.8</version>
        </dependency>
        
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.194</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.7.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.7.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>          
            <groupId>org.fusesource.jansi</groupId>
            <artifactId>jansi</artifactId>
            <version>2.3.2</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
            <type>jar</type>
        </dependency>        
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>example</id>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>xxxx.xxxxx.service.demonstration.MainDemo</mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>

I suspect that it’s something to do with how maven is building the jar, since it works fine on the IDE. I have tried to utilize different eclipselink versions too, but that didn’t seem to help (I started this project using 2.5.2 but updated after I had problems due to incompatibilities with some Java 8 features)

maven – How do I use token auth for Github Packages from Gradle?

In the repository section of your gradle.build.kts, include the following:

repositories {
    ...
    maven("https://maven.pkg.github.com/<OWNER>/<GIT_REPO>") {
        credentials(HttpHeaderCredentials::class) {
            name = "Authorization"
            value = "Bearer ${project.findProperty("gpr.token") as String}"
        }
        authentication {
            create<HttpHeaderAuthentication>("header")
        }
    }
}

Replacing <OWNER> with the name of the user or organization that owns the repo and and <GIT_REPO> with the name of the git repository that generates the package. You then add the token you generated on https://github.com/settings/tokens to gradle.properties in the same directory as your build.gradle.kts. It should look like:

gpr.token=<Token, without quotes>

The file may already exist with other settings, you don’t need to remove them. DO NOT COMMIT THIS FILE.

If this still does not work, verify that the token you generated has the read:packages permission. If it doesn’t, you’ll need to generate a new token.

Hopefully this saves you the 4 hours it took me to figure out what was happening.

java – Pass external jar to Maven 3.2.5 install goal without modifying pom.xml

I have an old Eclipse Maven Project wich make use of JDK 1.6 and Maven 3.2.5.
The project is built with a set of existing Maven Run Configuration options.

I am in need of including an external .jar.
I know that the best option would be to add it as a dependency, but as I don’t want to modify the original pom.xml, I am looking for alternatives.

I have tried to add the jar as a classpath argument in the “Main” tab of Run Configurations panel with no luck.

The jar is also added to the project build path, and infact Eclipse is not showing any class compilation error. But Maven goal just fail as it’s not finding the class dependency.

maven jib – JIB image creation time when inside executions tag

I am trying to creating images where image creation time is git commit time (in a profile). Default should be current time. Its working for the following configuration:

  <properties>
    <java.version>11</java.version>
    <spring-cloud.version>2020.0.1</spring-cloud.version>
    <image.creation.time>USE_CURRENT_TIMESTAMP</image.creation.time>
  </properties>
  .
  .Dependencies
  .
  <profiles>
    <profile>
      <id>git-time</id>
      <build>
        <plugins>
          <plugin>
            <groupId>pl.project13.maven</groupId>
            <artifactId>git-commit-id-plugin</artifactId>
            <executions>
              <execution>
                <phase>initialize</phase>
              </execution>
            </executions>
            <configuration>
              <generateGitPropertiesFile>false</generateGitPropertiesFile>
              <includeOnlyProperties>
                <includeOnlyProperty>^git.commit.time$</includeOnlyProperty>
              </includeOnlyProperties>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <properties>
        <image.creation.time>${git.commit.time}</image.creation.time>
      </properties>
    </profile>
  </profiles>

  <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>2.8.0</version>
        <configuration>
          <from>
            <image>gcr.io/distroless/java-debian10:11</image>
          </from>
          <to>
            <image>${project.artifactId}</image>
            <tags>
              <tag>${project.version}</tag>
            </tags>
          </to>
          <container>
            <creationTime>${image.creation.time}</creationTime>
            <mainClass>com.example.test1.Test1Application</mainClass>
            <ports>
              <port>8080</port>
            </ports>
          </container>
        </configuration>
      </plugin>
    </plugins>
  </build>

Command

mvn -Pgit-time -Dmaven.test.skip=true package jib:dockerBuild

enter image description here

If I put the configuration inside execution, it doest work as expected:

 <properties>
    <jib.from.image>gcr.io/distroless/java-debian10:11</jib.from.image>
    <jib.to.image>${project.artifactId}</jib.to.image>
    <jib.to.tags>${project.version},latest</jib.to.tags>
    <jib.container.ports>8080</jib.container.ports>
    <image.creation.time>USE_CURRENT_TIMESTAMP</image.creation.time>
  </properties>
  .
  ...Dependencies...
  .
  <profiles>
    <profile>
      <id>git-time</id>
      <build>
        <plugins>
          <plugin>
            <groupId>pl.project13.maven</groupId>
            <artifactId>git-commit-id-plugin</artifactId>
            <executions>
              <execution>
                <phase>initialize</phase>
              </execution>
            </executions>
            <configuration>
              <generateGitPropertiesFile>false</generateGitPropertiesFile>
              <includeOnlyProperties>
                <includeOnlyProperty>^git.commit.time$</includeOnlyProperty>
              </includeOnlyProperties>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <properties>
        <image.creation.time>${git.commit.time}</image.creation.time>
      </properties>
    </profile>
  </profiles>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>2.8.0</version>
        <executions>
          <execution>
            <id>distroless-image</id>
            <!--<phase>package</phase>-->
            <goals>
              <goal>build</goal>
            </goals>
            <configuration>
              <container>
                <creationTime>${image.creation.time}</creationTime>
                <appRoot>/app</appRoot>
                <entrypoint>
                  java,-cp,/app/classes:/app/resources:/app/libs/*,com.example.test2.Test1Application
                </entrypoint>
                <user>nonroot:nonroot</user>
                <workingDirectory>/home/nonroot</workingDirectory>
              </container>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

This time running the same command, produces an image with 1970.

enter image description here

Can someone help in figuring out what is different if I want to use executions instead and what the creationTime is not taken? (I plan to have different execution)

Sample code can be seen here – https://github.com/dhananjay12/TestRepo/tree/master/test1/pom.xml
and https://github.com/dhananjay12/TestRepo/blob/master/test2/pom.xml

maven – How to use same java code for Appium/TestNG testing on local devices and on AWS Devicefarm

I want to use the same java code for testing apps on local devices and on AWS Devicefarm.
I am using maven, testng and appium to build and execute the tests.
The following lines of code have to be used for local test execution:

capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, WeConnect_ID_iOS_Common_Values.deviceName);
capabilities.setCapability(MobileCapabilityType.APP, WeConnect_ID_iOS_Common_Values.appPath);
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, WeConnect_ID_iOS_Common_Values.automationName);

These capabilities cannot be used on AWS Devicefarm.
I am trying to pass a parameter with the maven build for AWS Devicefarm

mvn -B clean package -DtestEnvironment=AWS -DskipTests=true –file Android/pom.xml

to the java executable to skip the capability setup for Device Name, App Path and Automation Name, but the parameter is not recognized in the java executable on AWS Devicefarm (it works locally with <mvn test -DtestEnvironment=AWS -DsuiteFile=”src/test/resources/testng.xml”>).

I try to read the parameter value from the java code with:

String testEnvironment=System.getProperty(“testEnvironment”);

Does anyone have an idea how to solve this?

java – What is the better way to save swagger code gen plugin generated model classes in spring boot maven application?

So, I am working on a spring boot maven project in Eclipse IDE. And here is my pom.xml.


<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>spring-swagger-codegen-api-client</artifactId>
    <name>spring-swagger-codegen-api-client</name>
    <packaging>jar</packaging>
    <url>https://github.com/swagger-api/swagger-codegen</url>
    <description>Swagger Java</description>
...
...ommited for brevity
...

    <build>
        <plugins>

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/customer-data-v2.json</inputSpec>
                <language>java</language>
                <configOptions>
                   <sourceFolder>swagger</sourceFolder>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
        </plugins>
    </build>

</project>

So when I compile the project using mvn compile it executes swagger code gen plugin and outputs all the generated classes to swagger folder under target folder.

And I am using swagger code gen plugin to generate all the model classes using the customer json schema which it currently outputs to swagger sub folder under target folder.

So I know that I can keep all the generated classes under target folder itself as maven executes swagger plugin before compiling the actual source code. So right now there is no issue with it.

But all the generated classes are Model classes which are used for processing request and response data. So currently there is no issue in doing so, but in future we might add additional functionality which might require updates to generated model classes and may be difficult to update them from target folder.

So my main question is should I move all the generated pojo classes to something like src/main/org/**/* folder or keep the model classes inside target folder itself? What is the better approach including other alternative?

java – Error en IntelliJ IDEA con maven

Al ejecutar el programa me aparecen los siguientes errores:
introducir la descripción de la imagen aquí

Este error me sale justo después de que el usuario introduzca el nombre del usuario

La base de datos esta relacionada asi:

Los nombres subrayados son los nombres de las tablas

POM:

introducir la descripción de la imagen aquí

Conexión:

 private final String SERVER = "localhost";
    private final int PORT = 3306;
    private final String NAME = "colegio";
    private final String USER = "user";
    private final String PASS = "root";

    private Connection conn;

    /**
     * Crea un nuevo controlador
     */
    public Controller () {

        try {
            Class.forName("org.mariadb.jdbc.Driver");

            String url = "jdbc:mariadb://" + SERVER + ":" + PORT + "/" + NAME;
            this.conn = DriverManager.getConnection(url, USER, PASS);

        } catch (Exception e) {
            System.err.println("Ha ocurrido un error al conectar con la base de datos");
            e.printStackTrace();
        }
    }