انتقل إلى المحتوى
أمين أبوزيد
JNR-002

Maven بعمق

  • 8 درس
  • 88 دقيقة قراءة
  • 3 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • نطاقات الاعتماديات (Dependency scopes)
  • الاعتماديات المتعدية (Transitive dependencies)
  • BOMs
  • الإضافات (Plugins)
  • أساسيات المشاريع متعددة الوحدات
  • البناء القابل للتكرار (Reproducible builds)

تعلّم أولًا

88 دقيقة قراءة · 3 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Choose the correct dependency scope (compile, provided, runtime, test) for a dependency.
  2. Inspect the dependency tree, explain transitive dependencies, and resolve a version conflict.
  3. Import a BOM to align versions and explain why Spring Boot uses one.
  4. Configure common plugins (compiler, surefire, failsafe) and split a project into a multi-module build.
  5. Explain what makes a build reproducible and use the Maven Wrapper.

الدروس

  1. 01نطاقات الاعتماديات (Dependency scopes)11 د قراءة
  2. 02الاعتماديات المتعدية وdependency:tree11 د قراءة
  3. 03تعارض الإصدارات وإدارة الاعتماديات11 د قراءة
  4. 04BOMs11 د قراءة
  5. 05الإضافات ودورة حياة البناء: نظرة ثانية11 د قراءة
  6. 06المشاريع متعددة الوحدات11 د قراءة
  7. 07البناء القابل للتكرار وMaven Wrapper11 د قراءة
  8. 08عرض عملي: حل تعارض في الاعتماديات باستخدام dependency:tree11 د قراءة

المختبر والتمارين

Lab

JNR-002-LAB1 · Shop multi-module

Outcomes: 1–5 · Time: ~2 h Split the project into shop-core and shop-cli with a parent POM, central dependency management, and the Maven Wrapper. A version conflict is planted in the starter; diagnose it with dependency:tree and fix it. Acceptance: ./mvnw verify passes on a clean clone; no version is hard-coded in a child module; the README explains the conflict cause.

Exercises (assessment: fix a broken multi-module build and explain the cause, plus six exercises)

IDOutcomeTask
JNR-002-EX011Pick a scope for each: JUnit, Postgres JDBC driver, Servlet API (server provides it), Guava used in your code.
JNR-002-EX022Run dependency:tree on a project and name one transitive dependency and the dependency that brought it.
JNR-002-EX032Two libraries need commons-lang3 3.9 and 3.14. Which does Maven choose by default? Show two ways to control it.
JNR-002-EX043Import a BOM and add one dependency without a version. Explain why this is safer.
JNR-002-EX054Configure the compiler plugin for the Java release, and say which plugin runs *Test and which runs *IT.
JNR-002-EX064Create a parent POM with two modules, where one depends on the other. Show the build order.
JNR-002-EX075Add the wrapper, remove Maven from your PATH, and run the build. List three things that make a build reproducible.
أظهر الحلول
  • EX01 JUnit test; JDBC driver runtime; Servlet API provided; Guava compile.
  • EX02 Example: failureaccess brought by guava. Read it from the tree indentation.
  • EX03 The nearest declaration wins; if equal distance, the first declared. Control with dependencyManagement (pin) or a direct dependency or exclusion.
  • EX04 <scope>import</scope><type>pom</type> in dependencyManagement; the version comes from the BOM, so libraries match.
  • EX05 <release> in maven-compiler-plugin; Surefire runs *Test; Failsafe runs *IT.
  • EX06 The parent lists <modules>; the dependency module builds first (Maven sorts by dependencies).
  • EX07 mvn wrapper:wrapper, then ./mvnw verify. Reproducible: fixed versions (no ranges), wrapper-pinned Maven, same Java release.
  • All outcomes are also covered by the lab; outcome 5 is covered by quiz Q10.

الاختبار

Outcomes: O1 scopes · O2 dependency tree and conflicts · O3 BOMs · O4 plugins and multi-module · O5 reproducible builds.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1Which scope for JUnit?O1
  2. 2Which scope for a database driver used only at run time?O1
  3. 3Which command prints the dependency tree?O2
  4. 4A transitive dependency is one that:O2
  5. 5In a version conflict, Maven by default picks:O2
  6. 6What is a BOM?O3
  7. 7Why does Spring Boot use a BOM?O3
  8. 8Which plugin runs integration tests (*IT)?O4
  9. 9A parent POM uses packaging:O4
  10. 10The Maven Wrapper ensures:O5

الجزء العملي

Seven exercises JNR-002-EX01 to EX07 plus the lab; for the assessment, fix a broken multi-module build and explain the cause. Pass: at least 8 of 10 quiz answers, six exercises correct, and ./mvnw verify green on a clean clone.

أخطاء شائعة

Hard-coded versions in every module; compile scope for test libraries; ignoring dependency convergence.

التقييم

Fix a broken multi-module build and explain the cause.

الصلة بالمسار الوظيفي

Every Spring Boot project; dependency security (MID-053).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.