How to add conflicts in D8 info.yml? I want to know how to add conflicts in D8 info.yml.

I tried like this in D8 .info.yml:

name: Example
type: module
description: some example.
core: 8.x
package: Other
dependencies:
  - menu_ui
conflicts:
  - module1
  - module2


and in .install file

&lt;?php
/**
 * Implements hook_requirements().
 */
function example_requirements($phase) {
  $requirements = [];

  switch ($phase) {
    // Called while the module is installed.
    case 'install':
    if (\Drupal::moduleHandler()-&gt;moduleExists('module1')) {
        $requirements[] = [
          'title' =&gt; t('Module 1'),
          'value' =&gt; t('Module 1'),
          'description' =&gt; t('Module 1 conflicts with example.'),
          'severity' =&gt; REQUIREMENT_ERROR,
        ];
      }
      break;
  }

  return $requirements;
}


But in D7 it is working:

name = Example
description = some example.
core = 7.x
dependencies[] = menu
package = Other
conflicts[] = module1
conflicts[] = module2


While enabling my example module it is not showing any conflict error in D8. 


  Installation Order:
  
  1) Fresh Drupal installation.
  
  2) Module 1
  
  3) Module 2
  
  4) Example module(here i need to show module1 and 2 are present while
  installing)
It seems that this is not implemented yet. Related issue is here.

An alternative would be to use hook_requirements() in your module's .install file. You can check here if the conflicting module is present during the installation process and prevent the system from installing the module.

Here's example code that would go in your module's .install file:

/**
 * Implements hook_requirements().
 */
function YOUR_MODULE_requirements($phase) {
  $requirements = [];

  switch ($phase) {
    // Called while the module is installed.
    case 'install':
    // Called during regular use of the website.
    case 'runtime':
    // Called while the update.php is being executed.
    case 'update':
      // Do not allow administrators to install the module if conflicting module
      // is already installed.
      //
      // You can move this code to any other phase as well.
      if (\Drupal::moduleHandler()-&gt;moduleExists('ARCH_ENEMY_OF_YOUR_MODULE')) {
        $requirements[] = [
          'title' =&gt; t('Name of your module'),
          'value' =&gt; t('Arch enemy module'),
          'description' =&gt; t('Explain that administrators need to uninstall the module before proceeding.'),
          'severity' =&gt; REQUIREMENT_ERROR,
        ];
      }
      break;
  }

  return $requirements;
}


You can see a working example of hook_requirements() in my Drupal 8 boilerplate repo on Github.

Hope this helps.