asyncapi/jasyncapi

Cannot load class AND Scanner SubTypesScanner was not configured

Closed this issue · 12 comments

Hi,

I am facing a strange scenario. We would like to utilize the Async API and the asyncapi-maven-plugin in our maven project.

We have the example StreetligthsAsyncAPI.java from this github page under src/main/java in the package of com.example.asyncapi.

We have

<dependency>
	<groupId>com.asyncapi</groupId>
	<artifactId>asyncapi-core</artifactId>
	<version>1.0.0-EAP-1</version>
</dependency>

and

<build>
        <plugins>
            <plugin>
			    <groupId>com.asyncapi</groupId>
			    <artifactId>asyncapi-maven-plugin</artifactId>
		    	<version>1.0.0-EAP-1</version>
                <configuration>
                   	<packageNames>
                   		<packageName>com.example.asyncapi</packageName>
                   	</packageNames>
                   	<classPath>${project.basedir}/src/main/java</classPath>
            	</configuration>
			</plugin>
        </plugins>
</build>

And this (used command: mvn com.asyncapi:asyncapi-maven-plugin:generate) generates the following error:
[INFO] --- asyncapi-maven-plugin:1.0.0-EAP-1:generate (default-cli) @ asyncapi ---
[INFO] required parameters: checking...
[INFO] required parameters: ok
[INFO] generation strategy: checking...
[INFO] generation strategy: json
[INFO] schemas loader: looking for schemas
[INFO] [classes]: loading...
[INFO] [classes]: nothing to load
[INFO] [packages]: searching...
[INFO] [packages]: scanning 1 packages
[INFO] [packages]: scanning com.example.asyncapi
[classes]: can't load classes from com.example.asyncapi - Scanner SubTypesScanner was not configured

And if we try to set up the plugin configuration with className:

<build>
        <plugins>
            <plugin>
			    <groupId>com.asyncapi</groupId>
			    <artifactId>asyncapi-maven-plugin</artifactId>
		    	<version>1.0.0-EAP-1</version>
                <configuration>
                   	<classNames>
                   		<className>com.volvo.it.example.asyncapi.input.StreetlightsAsyncAPI</className>
                   	</classNames>
                   	<classPath>${project.basedir}/src/main/java</classPath>
            	</configuration>
			</plugin>
        </plugins>
</build>

And this (used command: mvn com.asyncapi:asyncapi-maven-plugin:generate) generates the following error:
[INFO] --- asyncapi-maven-plugin:1.0.0-EAP-1:generate (default-cli) @ asyncapi ---
[INFO] required parameters: checking...
[INFO] required parameters: ok
[INFO] generation strategy: checking...
[INFO] generation strategy: json
[INFO] schemas loader: looking for schemas
[INFO] [classes]: loading...
[INFO] [classes]: loading 1 classes
[INFO] [classes]: loading com.example.asyncapi.StreetlightsAsyncAPI
[classes]: can't load com.example.asyncapi.StreetlightsAsyncAPI - com.example.asyncapi.StreetlightsAsyncAPI

The same happens if we use <packageNames>com.volvo.it.example.asyncapi.input</packageNames> or <classNames>com.volvo.it.example.asyncapi.input.StreetlightsAsyncAPI</classNames>.

Can you please help us what we miss here?

Thank you and best regards,
Laszlo

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@karsai1993 hi.

I'll try to reproduce your problem tonight.

@karsai1993 yep, I was right. Problem was in class-loader.

I was ensured that it was fixed in 1.0.0-EAP-1 release. Anyway, it was a typo in SchemaGeneratorMojo.kt . Should be:

override fun resolveClassLoader(): ClassLoader {
   val urls = mutableSetOf<URL>()

   project.runtimeClasspathElements.forEach {
       urls.add(File(it).toURI().toURL())
   }

   return URLClassLoader(urls.toTypedArray(), Thread.currentThread().contextClassLoader)
}

Can you install plugin locally and check that everything works as expected?

I'm not sure that I will be on a time to patch, check, build and release a new version today

https://github.com/Pakisan/jasyncapi/releases/tag/idea-EAP-1

@Pakisan, thanks for taking time on this.
I could not run the project locally, the issue I am facing now:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-source-plugin:2.2.1:jar-no-fork (attach-sources) on project asyncapi: Execution attach-sources of goal org.apache.maven.plugins:maven-source-plugin:2.2.1:jar-no-fork failed: A required class was missing while executing org.apache.maven.plugins:maven-source-plugin:2.2.1:jar-no-fork: org/codehaus/plexus/archiver/ArchiverException

However, I am wondering if you could/are willing to create a version that I can use instead of the 1.0.0-EAP-1 that has this fix?

@karsai1993

I could not run the project locally, the issue I am facing now:

Which project did you try to run? Jasynapi?

However, I am wondering if you could/are willing to create a version that I can use instead of the 1.0.0-EAP-1 that has this fix?

I created new snapshot on 19 of November. It's located here: https://github.com/Pakisan/jasyncapi/releases/tag/idea-EAP-1. Did you try to install this version of plugin from this release locally?

Can you install plugin locally and check that everything works as expected?

I'm not sure that I will be on a time to patch, check, build and release a new version today

https://github.com/Pakisan/jasyncapi/releases/tag/idea-EAP-1

Hi @Pakisan and @karsai1993

I have the same issue too, any news?

Thanks!

@tmoreno Hi.

Did you check this build?

Can you install plugin locally and check that everything works as expected?

I'm not sure that I will be on a time to patch, check, build and release a new version today

https://github.com/Pakisan/jasyncapi/releases/tag/idea-EAP-1

I've installed the plugin with this command:

mvn install:install-file -Dfile=asyncapi-maven-plugin-1.0.0-EAP-1.jar -DgroupId=com.asyncapi -DartifactId=asyncapi-maven-plugin -Dversion=1.0.0-EAP-1 -Dpackaging=jar -DgeneratePom=true

And i have this error:

[ERROR] Failed to execute goal com.asyncapi:asyncapi-maven-plugin:1.0.0-EAP-1:generate (default) on project doc: Execution default of goal com.asyncapi:asyncapi-maven-plugin:1.0.0-EAP-1:generate failed: A required class was missing while executing com.asyncapi:asyncapi-maven-plugin:1.0.0-EAP-1:generate: com/asyncapi/plugin/core/AsyncAPISchemaGenerator
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>com.asyncapi:asyncapi-maven-plugin:1.0.0-EAP-1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/home/MYUSER/.m2/repository/com/asyncapi/asyncapi-maven-plugin/1.0.0-EAP-1/asyncapi-maven-plugin-1.0.0-EAP-1.jar
[ERROR] urls[1] = file:/home/MYUSER/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------

As a workaround I'm generating the spec file using a unit test

This issue has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️

This issue has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️

Hi all,

I had the same issue and tried to change the Mojo code (SchemaGeneratorMojo) as implementation of the AsyncAPISchemaGenerator like @Pakisan said and build locally and it works.

Thanks @Pakisan

This issue has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️