Using Composer on Joomla 4 Topic is solved

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
tmisiunas
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Wed May 25, 2011 8:37 pm

Using Composer on Joomla 4

Post by tmisiunas » Mon Mar 25, 2024 9:08 pm

Hi.
I am trying to install the google/apiclient with Composer.
I go to mysite/libraries folder and then run the command
composer require google/apiclient:^2.0
And then Composer starts removing all the joomla libraries.
I do not understand why.
Please, help me.
I am in stuck with that.
P.S. Joomla version 4.1.2
You do not have the required permissions to view the files attached to this post.

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2910
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Using Composer on Joomla 4

Post by SharkyKZ » Mon Mar 25, 2024 9:36 pm

Joomla does not support managing Composer dependencies. You need to ship the custom vendor folder in your extension. Using prefixer may be need to avoid conflicts with core dependencies.

tmisiunas
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Wed May 25, 2011 8:37 pm

Re: Using Composer on Joomla 4

Post by tmisiunas » Mon Mar 25, 2024 11:49 pm

What about this article
https://docs.joomla.org/J3.x:Using_Composer_with_Joomla
What do You mean about to ship the custom vendor?
I can copy all the vendors to our libraries/vendor folder.
But what about autoloading?
Or should I use the php include/require commands in my extension?
Thanks a lot for Your help.

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2910
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Using Composer on Joomla 4

Post by SharkyKZ » Tue Mar 26, 2024 6:24 am

The last paragraph in that article clearly says you can't install extra libraries. It also explains why you're seeing this behavior — Joomla does not ship composer.json. Thus any composer command you run creates a new project from scratch with a new composer.json and so all existing packages are uninstalled.

To autoload classes you have to load just the vendor/autoload.php file.

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 330
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: Using Composer on Joomla 4

Post by MarkRS » Tue Mar 26, 2024 8:49 am

I am (successfully) using the Google API.

I have the composer json and lock files in my component's administrator directory and therefore the vendor directory directory is there too. In order not to interfere with Joomla classes I've used Scoper to adjust the class names. This works perfectly well.
It's a community, the more we all contribute, the better it will be.

User avatar
Maradona
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 154
Joined: Fri Aug 30, 2013 2:08 pm
Location: Argentina

Re: Using Composer on Joomla 4

Post by Maradona » Wed Mar 27, 2024 12:35 am

MarkRS wrote:
Tue Mar 26, 2024 8:49 am
In order not to interfere with Joomla classes I've used Scoper to adjust the class names.
What is Scoper? :laugh:

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 330
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: Using Composer on Joomla 4

Post by MarkRS » Wed Mar 27, 2024 11:09 am

Maradona wrote:
Wed Mar 27, 2024 12:35 am
What is Scoper? :laugh:
GitHub - humbug/php-scoper: Prefixes all PHP namespaces in a file ...
PHP-Scoper is a tool which essentially moves any body of code, including all dependencies such as vendor directories, to a new and distinct namespace. Goal PHP-Scoper's goal is to make sure that all code for a project lies in a distinct PHP namespace.

The Google API uses names that the main Joomla js uses, so Scoper, moving the entire Google API (that I've loaded), keeps it separate from Joomla and prevents interference. At least, that's the way it seems to me. 8)
It's a bit like the hand of God for js :D
It's a community, the more we all contribute, the better it will be.

User avatar
Maradona
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 154
Joined: Fri Aug 30, 2013 2:08 pm
Location: Argentina

Re: Using Composer on Joomla 4

Post by Maradona » Wed Mar 27, 2024 4:32 pm

Good info...thank you! 8)

tmisiunas
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Wed May 25, 2011 8:37 pm

Re: Using Composer on Joomla 4

Post by tmisiunas » Thu Mar 28, 2024 10:03 pm

Thanks a lot to SharkyKZ.
You saved my life.


Post Reply

Return to “Joomla! 4.x Coding”