nanosai / modrun

A Java application launcher and class loader which can load and run classes directly from Maven repositories and resolve dependencies at runtime.
Apache License 2.0
97 stars 12 forks source link

Few questions about modrun #1

Open PhantomYdn opened 7 years ago

PhantomYdn commented 7 years ago

It looks very interesting library for using in our project http://orienteer.org for dynamic loading of plugins from maven repository. But I have several questions:

1) Can library support downloading from central maven repository? From private http-enabled repository? Any plans about that? 2) Is there possibility to setup several repositories instead of just one? It's epsecially interesting for remote repositories? 3) When do you plan to publish in maven central?

jjenkov commented 7 years ago

1) Right now ModRun cannot download from a remote repository, but we plan to add that. We have not yet decided if ModRun should download and store JAR files in your local Maven repository, or download them directly from the remote repositories every time. It is probably better to download and store in the local Maven repository and run from there in the future.

2) Once ModRun can download from a remote repository, we will probably add the concept of repository chains, where multiple repositories can be linked together. ModRun will try to download from each of these repositories in the linked sequence. Exactly how that will work we need to analyze a bit to make sure we hit the needs of developers.

It is still early in the life of ModRun. We have some simple proof-of-concept working now, but we still have some way to go before ModRun is fully functional.

PhantomYdn commented 7 years ago

I think loading from local maven would be OK if there will be possiblity to "upload" into repository required file. Also it's not clear why for every dependency separate class loader required in your code. Could you please clarify?

jjenkov commented 7 years ago

Using a separate classloader for every dependency makes it possible to use two different versions of a dependency at the same time, in the same application. This would not be possible with a single classloader that loads all the classes into the JVM.

PhantomYdn commented 7 years ago

Is it possible to make it configurable? Otherwise it will be war of class cast exceptions. And btw, maven during compile time use latest version of artifact if there are 2+ versions coming through dependencies.

And just in case: did you work with https://github.com/kamranzafar/JCL ?

jjenkov commented 7 years ago

It could be possible to make it configurable - one classloader or one per module.

There should not be any ClassCastExceptions - as the classloader will take care of loading the correct version of a class when needed. This can be detected via the dependency graph for a module.

Maven only uses the latest version of a dependency if it needs to compile against it. But, if your module uses dependency A and B, and A and B are both precompiled, Maven won't care about the dependencies of A and B at compile time of your module. If A depends on C version 1.0 and B depends on C version 2.0 - then Maven won't detect that when compiling your module. It will no be detected until runtime. We have had exactly this problem with Bouncy Castle at work at the moment.

ModRun would solve this problem simply by loading C v. 1.0 for A and C v. 2.0 for B - no conflicts. Detected via the Maven dependency graph for the modules - invisible to A and B - and your module too. At least that is the theory - I still need to implement it - but I have a proof-of-concept implementation of something similar already.

PhantomYdn commented 7 years ago

Actually will be happy to see your library in maven central as soon as you can release it:)

We have some heavy modules which can be added. Keeping all together is overkill. Your library will help ability dynamically attach new modules.

jjenkov commented 7 years ago

The latest commit contains the core idea of how to load dependencies recursively from transitive dependencies. It has not yet been tested. I just pushed the main ideas. I will begin the testing soon.

jjenkov commented 7 years ago

Just created a release which have the basic transitive dependency class loading working. From here on it is mostly testing, polishing and adding more features, like downloading modules from remote Maven repositories.

PhantomYdn commented 7 years ago

That's cool:) Thank you. But not yet in maven rep seems to me....

jjenkov commented 7 years ago

No, not yet in the central Maven repo.