使用Maven设置Drupal PHP项目

时间:2022-01-29 12:02:15

What do I want to achieve?

We are currently working on a PHP project that uses Drupal.

我们目前正在开发一个使用Drupal的PHP项目。

I desperately want to learn how to create a One-step build for the whole project. Preferably by using something new (for me) that seems very powerful: Maven

我非常想学习如何为整个项目创建一步构建。最好使用一些看似非常强大的新东西(对我来说):Maven

Basically I want to automate the following process:

基本上我想自动化以下过程:

  1. Checkout Drupal from the official CVS repository.
  2. 从官方CVS存储库中检出Drupal。

  3. Checkout official 3rd party modules from their respective CVS repositories.
  4. 从各自的CVS存储库中查看官方第三方模块。

  5. Checkout our custom modules from our mercurial repository.
  6. 从我们的mercurial存储库中查看我们的自定义模块。

  7. Copy/move all the modules to the appropriate directory within Drupal.
  8. 将所有模块复制/移动到Drupal中的相应目录。

  9. Checkout and install our custom theme.
  10. 签出并安装我们的自定义主题。

  11. Add a custom drupal installation profile.
  12. 添加自定义drupal安装配置文件。

  13. Create a new MySQL database schema.
  14. 创建一个新的MySQL数据库模式。

  15. If possible, automate the drupal db connection setup.
  16. 如果可能,自动执行drupal db连接设置。

In the future I would like to run this build on a Hudson (or any other) continues integration server.

在将来,我想在Hudson(或任何其他)继续集成服务器上运行此构建。

Why Maven? (why not Ant or Phing?)

Other than the desire to learn something new (I have used Ant before) I think the dependency management of Maven might work well for the drupal modules.

除了学习新东西的愿望(我以前使用过Ant)之外,我认为Maven的依赖管理可能对drupal模块有效。

Do you think this is enough reason to use Maven, even though Maven was not originally intended for PHP projects? I know Ant was not originally used for PHP either, but there are far more examples of people using Ant and PHP together.

您是否认为这是使用Maven的充分理由,即使Maven最初并非用于PHP项目?我知道Ant最初也不是用于PHP,但是有更多人将Ant和PHP结合使用的例子。

BTW I think I will switch to Ant if I can't get Maven to work soon. The procedural style of Ant is just easier for me to understand.

顺便说一下,如果我不能让Maven尽快工作,我想我会切换到Ant。 Ant的程序风格让我更容易理解。

What do I have so far?

I have a pom.xml file, that uses the SCM plugin, to checkout the drupal source. When I run:

我有一个使用SCM插件的pom.xml文件来检查drupal源代码。当我跑:

mvn scm:checkout

the source is checked out into a new directory:

将源签出到新目录中:

target/checkout

When I try:

当我尝试:

mvn scm:bootstrap

it complains about the install goal not being defined.

它抱怨没有定义安装目标。

Here is the pom.xml:

这是pom.xml:

<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>com.example</groupId>
  <artifactId>drupal</artifactId>
  <version>1.0</version>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-scm-plugin</artifactId>
          <version>1.1</version>
          <configuration>
            <username>anonymous</username>
            <password>anonymous</password>
          </configuration>
      </plugin>
    </plugins>
  </build>
  <scm>
    <connection>scm:cvs:pserver:cvs.drupal.org:/cvs/drupal:drupal</connection>
    <developerConnection>scm:cvs:pserver:cvs.drupal.org:/cvs/drupal:drupal</developerConnection>
    <tag>DRUPAL-6-12</tag>
    <url>http://cvs.drupal.org/viewvc.py/drupal/drupal/?pathrev=DRUPAL-6</url>
  </scm>
</project>

Finally, what are my questions?

  • Is Maven the wrong tool for this?
  • Maven是错误的工具吗?

If no,

  • How would you do this?
  • 你会怎么做?

  • Is it the scm:bootstrap goal that I should be using?
  • 是我应该使用的scm:bootstrap目标吗?

  • What is the Maven way of moving directories around on the file system?
  • 什么是在文件系统上移动目录的Maven方式?

  • Should the install goal be used to move the modules into the drupal directory?
  • 是否应该使用安装目标将模块移动到drupal目录中?

  • Currently all our custom modules are in one mercurial repository. Is it possible to create a pom.xml and checkout each module individually?
  • 目前,我们所有的自定义模块都在一个mercurial存储库中。是否可以创建一个pom.xml并单独检出每个模块?

  • Any general advice would be appreciated.
  • 任何一般建议将不胜感激。

Thanks for your time!

谢谢你的时间!

5 个解决方案

#1


Definitely you're not using Maven, here some thoughts:

肯定你没有使用Maven,这里有一些想法:

  • Maven is a Java build tool and dependency management software with a well-defined lifecycle which goes like this: validate, compile, test, package, integration-test, verify, install, deploy. What you are using is the scm plugin which can stick to any of the phases defined here and perform some actions but unless you make complicated changes in the POM (I haven't heard of anyone doing this) the lifecycle will continue being executed.
  • Maven是一个Java构建工具和依赖管理软件,具有明确定义的生命周期,如下所示:验证,编译,测试,打包,集成测试,验证,安装,部署。你正在使用的是scm插件,它可以坚持这里定义的任何阶段并执行一些操作,但除非你在POM中进行复杂的更改(我没有听说有人这样做),生命周期将继续执行。

  • Maven also is designed to package JARs, WARs and with the use of some plugins EARs, SARs, RARs (not that RARs) and some other files; you might have to program a new plugin to get the type of packages you expect or use the assembly plugin which will make things more complicated.
  • Maven还设计用于打包JAR,WAR以及使用一些插件EAR,SAR,RAR(不是那些RAR)和其他一些文件;你可能需要编写一个新插件来获得你期望的软件包类型,或者使用程序集插件会使事情变得更复杂。

Because of the previous points, there is no command for Maven to move the files into an specific directory (not a native one) and you shouldn't invoke install phase to copy the files to any other location than the local repository. What you're doing is like taking a laundry machine and converting it into a blender.

由于之前的观点,Maven没有命令将文件移动到特定目录(而不是本机目录),您不应调用安装阶段将文件复制到本地存储库以外的任何其他位置。你正在做的就像洗衣机并将其转换成搅拌机。

After reading what you want to do with your project I'd suggest you to create a script (shell script or batch script depending on your OS) for doing the job. SVN and CVS has command line tools which can be invoked from inside your build scripts. I guess you opted for Maven, among other reasons, because Hudson and many other Continuous Integration software are well integrated with it but you can use them with scripts too.

在阅读了您想要对项目执行的操作之后,我建议您创建一个脚本(shell脚本或批处理脚本,具体取决于您的操作系统)来完成工作。 SVN和CVS具有可以从构建脚本中调用的命令行工具。我猜你选择了Maven,除了其他原因,因为Hudson和许多其他的持续集成软件都很好地集成了它,但你也可以将它们与脚本一起使用。

If you are comfortable using Ant and you consider using it will ease the building time of your app I think is not as bad ;) (I haven't used Ant for other purposes than Java projects)

如果你习惯使用Ant而你考虑使用它会减轻你的应用程序的构建时间我觉得不是那么糟糕;)(我没有将Ant用于除Java项目之外的其他目的)

#2


I'm 98% certain that what you really need is Drush Make, which can recursively build Drupal projects, provided they provide their own .make file listing their dependencies. It can download from multiple SCMs, web, patch files, and you can control where they get downloaded. It also support external libs, such as wysiwyg, PHP files, or JS libraries.

我98%肯定你真正需要的是Drush Make,它可以递归地构建Drupal项目,只要它们提供自己的.make文件列出它们的依赖项。它可以从多个SCM,Web,补丁文件下载,您可以控制它们下载的位置。它还支持外部库,例如wysiwyg,PHP文件或JS库。

See the Open Atrium make file for a sample of what it can do.

请参阅Open Atrium make文件以获取其可以执行的操作的示例。

#3


The Drush 'module' is a great tool for scripting out things in Drupal. But, beyond that, I think your approach of doing CVS checkouts for each 'build' is a little off base - unless you have -really- good reasons to have every chunk of the project in a separate repository, your best bet is to have fixed checkouts of Drupal core & contributed modules committed to your project's repository. Not only does this take out a dependency on a network connection and the stability of an external server but it allows you to have local modifications of the contributed modules (unfortunately, you're probably going to end up doing this somewhere down the line).

Drush'模块'是在Drupal中编写脚本的好工具。但是,除此之外,我认为你为每个'构建'做CVS检查的方法有点偏离基础 - 除非你有一个很好的理由让项目的每个块都在一个单独的存储库中,你最好的选择是修复了Drupal核心和提交给您项目存储库的贡献模块。这不仅取决于网络连接的依赖性和外部服务器的稳定性,而且它允许您对提供的模块进行本地修改(不幸的是,您可能最终会在某个地方执行此操作)。

Once you take out the requirement to do checkouts from multiple repositories, you'll probably notice that your task becomes -much- easier, leaving you with some simple MySQL manipulation and writing out a settings.php.

一旦你从多个存储库中取出了检查的要求,你可能会注意到你的任务变得更加容易,让你进行一些简单的MySQL操作并编写一个settings.php。

#4


The project http://www.php-maven.org know comes with a build plugin enabling the php world to maven (or the maven world for php projects). Version 2 snapshot can be found in our google groups (news thread available at https://groups.google.com/group/maven-for-php/t/e055e49c89ccb8c5?hl=de).

该项目http://www.php-maven.org知道附带一个构建插件,使php世界成为maven(或php项目的maven世界)。可以在我们的Google群组中找到第2版快照(新闻主题位于https://groups.google.com/group/maven-for-php/t/e055e49c89ccb8c5?hl=de)。

However this gives you a full control over the project and respects the default maven lifecycle so that the maven commands:

但是,这使您可以完全控制项目并尊重默认的maven生命周期,以便maven命令:

  • mvn clean
  • mvn package
  • mvn deploy
  • mvn site

will work correctly.

会正常工作。

Drupal support may be enabled in version 2.1 where we are focused on frameworks (zend, flow3...) and project types (web, cli, libs...). It would be to much to clearify wha maven is and how it can help you during php development. As Vistor Hugo stated on his early comment Mavens benefits are not only to execute a specific command manually but to embed the whole project structure and the whole project lifecycle via maven. Since the most php guys did not yet have contact to java and especially maven we are creating tutorials so that everyone has a fairly simple entry in the maven world.

可以在2.1版中启用Drupal支持,我们专注于框架(zend,flow3 ...)和项目类型(web,cli,libs ......)。要清除wha maven是什么以及它如何在php开发过程中对你有所帮助。正如Vistor Hugo在早期评论中指出的那样,Mavens的好处不仅仅是手动执行特定命令,而是通过maven嵌入整个项目结构和整个项目生命周期。由于大多数PHP人员还没有接触到java,尤其是maven,我们正在创建教程,以便每个人都可以在maven世界中进行相当简单的输入。

#5


I love maven, although I think it is very java specific as mentioned above.

我喜欢maven,虽然我认为它是非常具体的java,如上所述。

I had success to handle repeable task with phing. I used in a Zend project to prepare a build or just fasten the normal repetable tasks (eg. clean up db, load db dump).

我成功地用phing来处理可重复的任务。我在Zend项目中用于准备构建或只是固定正常的可重复任务(例如,清理db,加载db dump)。

Phing won't provide you complete lifecycle management as maven, but you can write yourself by hand. You can embed shell script commands to build.xml so you can use everything that you would use in a normal shell script. I prefer phing over normal shell script because it can handle dependent targets, so if your build.xml contains well designed targets that depend each other, you'll get very useful chains to achive specified goals.

Phing不会像maven一样为您提供完整的生命周期管理,但您可以手动编写自己。您可以将shell脚本命令嵌入到build.xml中,以便可以使用在普通shell脚本中使用的所有内容。我更喜欢phing over普通shell脚本,因为它可以处理依赖目标,因此如果你的build.xml包含相互依赖的精心设计的目标,你将获得非常有用的链来实现指定的目标。

It works for me.

这个对我有用。

Another great tool for drupal is drush which makes drupal administration scriptable. You can do lots of drupal specific things from console. I think you can call drush commands from phing scripts.

drupal的另一个很棒的工具是drush,它使drupal管理成为可编程的。你可以从控制台做很多drupal特定的事情。我想你可以从phing脚本调用drush命令。

#1


Definitely you're not using Maven, here some thoughts:

肯定你没有使用Maven,这里有一些想法:

  • Maven is a Java build tool and dependency management software with a well-defined lifecycle which goes like this: validate, compile, test, package, integration-test, verify, install, deploy. What you are using is the scm plugin which can stick to any of the phases defined here and perform some actions but unless you make complicated changes in the POM (I haven't heard of anyone doing this) the lifecycle will continue being executed.
  • Maven是一个Java构建工具和依赖管理软件,具有明确定义的生命周期,如下所示:验证,编译,测试,打包,集成测试,验证,安装,部署。你正在使用的是scm插件,它可以坚持这里定义的任何阶段并执行一些操作,但除非你在POM中进行复杂的更改(我没有听说有人这样做),生命周期将继续执行。

  • Maven also is designed to package JARs, WARs and with the use of some plugins EARs, SARs, RARs (not that RARs) and some other files; you might have to program a new plugin to get the type of packages you expect or use the assembly plugin which will make things more complicated.
  • Maven还设计用于打包JAR,WAR以及使用一些插件EAR,SAR,RAR(不是那些RAR)和其他一些文件;你可能需要编写一个新插件来获得你期望的软件包类型,或者使用程序集插件会使事情变得更复杂。

Because of the previous points, there is no command for Maven to move the files into an specific directory (not a native one) and you shouldn't invoke install phase to copy the files to any other location than the local repository. What you're doing is like taking a laundry machine and converting it into a blender.

由于之前的观点,Maven没有命令将文件移动到特定目录(而不是本机目录),您不应调用安装阶段将文件复制到本地存储库以外的任何其他位置。你正在做的就像洗衣机并将其转换成搅拌机。

After reading what you want to do with your project I'd suggest you to create a script (shell script or batch script depending on your OS) for doing the job. SVN and CVS has command line tools which can be invoked from inside your build scripts. I guess you opted for Maven, among other reasons, because Hudson and many other Continuous Integration software are well integrated with it but you can use them with scripts too.

在阅读了您想要对项目执行的操作之后,我建议您创建一个脚本(shell脚本或批处理脚本,具体取决于您的操作系统)来完成工作。 SVN和CVS具有可以从构建脚本中调用的命令行工具。我猜你选择了Maven,除了其他原因,因为Hudson和许多其他的持续集成软件都很好地集成了它,但你也可以将它们与脚本一起使用。

If you are comfortable using Ant and you consider using it will ease the building time of your app I think is not as bad ;) (I haven't used Ant for other purposes than Java projects)

如果你习惯使用Ant而你考虑使用它会减轻你的应用程序的构建时间我觉得不是那么糟糕;)(我没有将Ant用于除Java项目之外的其他目的)

#2


I'm 98% certain that what you really need is Drush Make, which can recursively build Drupal projects, provided they provide their own .make file listing their dependencies. It can download from multiple SCMs, web, patch files, and you can control where they get downloaded. It also support external libs, such as wysiwyg, PHP files, or JS libraries.

我98%肯定你真正需要的是Drush Make,它可以递归地构建Drupal项目,只要它们提供自己的.make文件列出它们的依赖项。它可以从多个SCM,Web,补丁文件下载,您可以控制它们下载的位置。它还支持外部库,例如wysiwyg,PHP文件或JS库。

See the Open Atrium make file for a sample of what it can do.

请参阅Open Atrium make文件以获取其可以执行的操作的示例。

#3


The Drush 'module' is a great tool for scripting out things in Drupal. But, beyond that, I think your approach of doing CVS checkouts for each 'build' is a little off base - unless you have -really- good reasons to have every chunk of the project in a separate repository, your best bet is to have fixed checkouts of Drupal core & contributed modules committed to your project's repository. Not only does this take out a dependency on a network connection and the stability of an external server but it allows you to have local modifications of the contributed modules (unfortunately, you're probably going to end up doing this somewhere down the line).

Drush'模块'是在Drupal中编写脚本的好工具。但是,除此之外,我认为你为每个'构建'做CVS检查的方法有点偏离基础 - 除非你有一个很好的理由让项目的每个块都在一个单独的存储库中,你最好的选择是修复了Drupal核心和提交给您项目存储库的贡献模块。这不仅取决于网络连接的依赖性和外部服务器的稳定性,而且它允许您对提供的模块进行本地修改(不幸的是,您可能最终会在某个地方执行此操作)。

Once you take out the requirement to do checkouts from multiple repositories, you'll probably notice that your task becomes -much- easier, leaving you with some simple MySQL manipulation and writing out a settings.php.

一旦你从多个存储库中取出了检查的要求,你可能会注意到你的任务变得更加容易,让你进行一些简单的MySQL操作并编写一个settings.php。

#4


The project http://www.php-maven.org know comes with a build plugin enabling the php world to maven (or the maven world for php projects). Version 2 snapshot can be found in our google groups (news thread available at https://groups.google.com/group/maven-for-php/t/e055e49c89ccb8c5?hl=de).

该项目http://www.php-maven.org知道附带一个构建插件,使php世界成为maven(或php项目的maven世界)。可以在我们的Google群组中找到第2版快照(新闻主题位于https://groups.google.com/group/maven-for-php/t/e055e49c89ccb8c5?hl=de)。

However this gives you a full control over the project and respects the default maven lifecycle so that the maven commands:

但是,这使您可以完全控制项目并尊重默认的maven生命周期,以便maven命令:

  • mvn clean
  • mvn package
  • mvn deploy
  • mvn site

will work correctly.

会正常工作。

Drupal support may be enabled in version 2.1 where we are focused on frameworks (zend, flow3...) and project types (web, cli, libs...). It would be to much to clearify wha maven is and how it can help you during php development. As Vistor Hugo stated on his early comment Mavens benefits are not only to execute a specific command manually but to embed the whole project structure and the whole project lifecycle via maven. Since the most php guys did not yet have contact to java and especially maven we are creating tutorials so that everyone has a fairly simple entry in the maven world.

可以在2.1版中启用Drupal支持,我们专注于框架(zend,flow3 ...)和项目类型(web,cli,libs ......)。要清除wha maven是什么以及它如何在php开发过程中对你有所帮助。正如Vistor Hugo在早期评论中指出的那样,Mavens的好处不仅仅是手动执行特定命令,而是通过maven嵌入整个项目结构和整个项目生命周期。由于大多数PHP人员还没有接触到java,尤其是maven,我们正在创建教程,以便每个人都可以在maven世界中进行相当简单的输入。

#5


I love maven, although I think it is very java specific as mentioned above.

我喜欢maven,虽然我认为它是非常具体的java,如上所述。

I had success to handle repeable task with phing. I used in a Zend project to prepare a build or just fasten the normal repetable tasks (eg. clean up db, load db dump).

我成功地用phing来处理可重复的任务。我在Zend项目中用于准备构建或只是固定正常的可重复任务(例如,清理db,加载db dump)。

Phing won't provide you complete lifecycle management as maven, but you can write yourself by hand. You can embed shell script commands to build.xml so you can use everything that you would use in a normal shell script. I prefer phing over normal shell script because it can handle dependent targets, so if your build.xml contains well designed targets that depend each other, you'll get very useful chains to achive specified goals.

Phing不会像maven一样为您提供完整的生命周期管理,但您可以手动编写自己。您可以将shell脚本命令嵌入到build.xml中,以便可以使用在普通shell脚本中使用的所有内容。我更喜欢phing over普通shell脚本,因为它可以处理依赖目标,因此如果你的build.xml包含相互依赖的精心设计的目标,你将获得非常有用的链来实现指定的目标。

It works for me.

这个对我有用。

Another great tool for drupal is drush which makes drupal administration scriptable. You can do lots of drupal specific things from console. I think you can call drush commands from phing scripts.

drupal的另一个很棒的工具是drush,它使drupal管理成为可编程的。你可以从控制台做很多drupal特定的事情。我想你可以从phing脚本调用drush命令。